Articles > AutoCAD.Net API

AutoCAD.Net API programming using VB.Net, C#.Net, AutoCAD Customization using .Net

You can program AutoCAD using VB.Net/C#.Net with following methos:

1. Using ObjectARX managed wrapper classes
2. Using AutoCAD COM APIs
3. Using combination of both

If you are currently using AutoCAD VBA then you can use AutoCAD COM APIs to start AutoCAD programming using .Net immediately.

Procedure to use AutoCAD COM API with .Net is explained below:

- Start Microsoft Visual Studio
- Create a new Class Library project in VB.Net
- Add reference to AutoCAD Type Library (acax17enu.tlb), AutoCAD / ObjectDBX Common Type Library (axdb17enu.tlb), acdbmgd.dll and acmgd.dll.
- Type the following code (This code creates a line)

Imports Autodesk.AutoCAD.Runtime

Public Class Class1
    CommandMethod("MyLine")> _
     Public Shared Sub CreateLine()

         Dim AcadApp As Autodesk.AutoCAD.Interop.AcadApplication
         Dim acaddoc As Autodesk.AutoCAD.Interop.AcadDocument
         Dim pt As Object
         Dim pt1 As Object

         AcadApp = GetObject(, "Autocad.Application")
         acaddoc = AcadApp.ActiveDocument

         pt = acaddoc.Utility.GetPoint(, "Pick point:")
         pt1 = acaddoc.Utility.GetPoint(pt, "Pick second point:")

         acaddoc.ModelSpace.AddLine(pt, pt1)

     End Sub
End Class

- Build Solutions
- Start AutoCAD
- Give NetLoad command
- Select dll file created by above application
- Once the loading is completed you can give MyLine command to take the trial of above program.