COM Interoperability (.NET)

Microsoft Visual Studio can utilize both native .NET and COM interfaces in the same project. By utilizing COM interop, you can migrate existing code that might have been written in Visual Basic 6 or VBA without having to completely rewrite it. To access the AutoCAD automation objects from a project created in Microsoft Visual Studio, create references to the following files:

Note: The previous mentioned type libraries are also available as part of the ObjectARX SDK.

These references will make the following primary interop assemblies available:

The interop assemblies are located in the global assembly cache; they map automation objects to their .NET counterparts.

After you reference the type libraries, you should import the Autodesk.AutoCAD.Interop and Autodesk.AutoCAD.Interop.Common namespaces into the code modules that will utilize the objects defined in the libraries, as in the following examples:

VB.NET
Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.Interop.Common
C#
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Interop.Common;

can declare variables based on objects defined in the libraries, as in the following examples:

VB.NET
Dim objAcApp As AcadApplication
Dim objLine As AcadLine
C#
AcadApplication objAcApp;
AcadLine objLine;

The interop assemblies can be helpful in making the transition from VBA to VB.NET. However, in order to take full advantage of everything that .NET and the AutoCAD .NET API have to offer, you will need to rewrite your existing VBA code.

You can get a pointer to a COM object from the corresponding .NET object by using the following properties from the following objects:

A COM object can be obtained from a .NET object using the FromAcadXxx static function. For example, Database.FromAcadDatabase gets the .NET database object from the COM database object.

Create and Reference the Application

AutoCAD .NET applications can utilize the same type library (acax25enu.tlb) as AutoCAD automation projects. The type library is located in <drive>:\Program Files\Common Files\Autodesk Shared.

AutoCAD .NET applications also use the same version-dependent ProgID for the CreateObject, GetObject, and GetInterfaceObject functions.

You can use the product ProgID to create a new instance of the AutoCAD application ("AutoCAD.Application"), and specify the major and minor number of the release to restrict your application to a specific release or all the releases that are binary compatible with each other.

For example,

Note: You must have the corresponding release installed that you are trying to create an instance of.

If you are using ActiveX/COM from an in-process DLL (Class Library) and want to reference the AutoCAD application object, you can use Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication property.