Question

For last two days I have looking for sample code with steps which may help me to understand the Autocad API. so I can use the code in C#.

[CommandMethod("LISTGEn")]
public static void ListEntities()
        {
            Document acDoc = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;

            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                // Open the Block table record for read
                BlockTable acBlkTbl;
                acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,OpenMode.ForRead) as BlockTable;

                // Open the Block table record Model space for read
                BlockTableRecord acBlkTblRec;
                acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],OpenMode.ForRead) as BlockTableRecord;

                int nCnt = 0;
                acDoc.Editor.WriteMessage("\nModel space objects: ");

                // Step through each object in Model space and
                // display the type of object found
                foreach (ObjectId acObjId in acBlkTblRec)
                {
                    acDoc.Editor.WriteMessage("\n" + acObjId.ObjectClass.DxfName);

                    nCnt = nCnt + 1;
                }
                acDoc.Editor.WriteMessage(nCnt.ToString());
                // If no objects are found then display a message
                if (nCnt == 0)
                {
                    acDoc.Editor.WriteMessage("\n No objects found");
                }

                // Dispose of the transaction
            }

        } 

I can run the above code, but it's not functioning properly. It's difficult for me to understand how to get it work with Autocad. I have OjectARX SDK referenced, I am working with VS2010 and Autocad 2012. Thank You for your help.

Was it helpful?

Solution

Ok, I got it only thing that is being required

1.) is to create a class library

2.) Then need to enter the above code in the class.

3.) Build your project by pressing F5.

4.) A DLL will be created in the bin/debug/ folder of your project

5.) Open Autocad.

6.) Write netload command.

7.) Select the DLL created and then write command "LISTGEN" and than kaboom it will show all the objects in your project.

OTHER TIPS

To avoid having to manually netload your dll, you can use a temporary fix for debugging and write a lisp file to do it for you

(Command "netload" "path/to/your/.dll")\n

Or you can use \\

Take a look at my github. The link is on my profile. Look over the reference library, it's highly simplified for object model manipulation.

If you have any questions feel free to email me.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top