Use COM Interoperability with .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 AutoCAD automation objects from a project created in Microsoft Visual Studio, create references to the following files:

NoteThe previous mentioned type libraries are also available as part of the ObjectARX SDK. For information on downloading and installing the ObjectARX SDK, see Components of the AutoCAD .NET API.

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 can declare AutoCAD-based variables in Microsoft Visual Studio, as in the following examples:

VB.NET

Dim objAcApp As Autodesk.AutoCAD.Interop.AcadApplication
Dim objLine As Autodesk.AutoCAD.Interop.Common.AcadLine

C#

Autodesk.AutoCAD.Interop.AcadApplication objAcApp;
Autodesk.AutoCAD.Interop.Common.AcadLine objLine;

Utilizing the interop assemblies can make the transitioning your VBA projects over to VB.NET much easier. 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.

Create and Reference the AutoCAD Application

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

AutoCAD 2012 .NET applications also use the same version-dependent ProgID for the CreateObject, GetObject, and GetInterfaceObject functions. For example, CreateObject ("AutoCAD.Application.18") allows you to create an instance of AutoCAD and get an object that represents the new instance of the application.