.NET API vs COM Interop API (AutoCAD Programming)

There seems to be a lot of confusion with folks about the difference between using the AutoCAD .net API vs the COM Interop API. They both hope to do the same things, but via different ways. Given a choice, I’d always recommend using the .net API because it is much more powerful. Or if you are familiar with C++ then go for ObjectARX API which gives you immense power. You may think that using .net API obviates the need to manage resources - but you’d be wrong: the .net API is simply a wrapper to the underlying unmanaged types. You have to explicitly use transactions or you have to otherwise explicitly dispose of objects after you’ve finished using them. Nevertheless, the .net API is still very good to use in certain instances.

In process - .net API

This means that the user has to first open AutoCAD. i.e. double click on the AutoCAD icon and start up AutoCAD. once AutoCAD is open and a drawing is opened, then the user has to type in a command: “NETLOAD” and has to select the a file - the result of all your programming/coding efforts. once that file is selected the user then has to run the command “AddLine”. The command will run as you have coded it. In order to do it this way you will need the .AutoCAD net API.

Out of Process – COM InterOp

In this case, you don’t necessarily have to manually open AutoCAD up. you create your own program, and you open it (much like you would open MS word etc) and your “AddLine” command would run without you, as a user, manually opening AutoCAD and netloading etc.. if you’re going down this path you need to use the COM interop API.

Using Both

If you really want to use the .net API, but did not want to manually netload, then you can use a combination of both of the above:

From the documentation:

If you need to create a stand-alone application to drive AutoCAD, it is best to create an application that uses the CreateObject and GetObject methods to create a new instance of an AutoCAD application or return one of the instances that is currently running. Once a reference to an AcadApplication is returned, you can then load your in-process .NET application into AutoCAD by using the SendCommand method that is a member of the ActiveDocumentproperty of the AcadApplication.

As an alternative to executing your .NET application in-process, could use COM interop for your application.

Hope this clear things up for you.

Written on June 14, 2017