How Do I Access Autocad Com Objects From Visual Studio?

I have stopped ignoring visual studio. I am having no issues accessing Com Activex objects from VB.Net with nearly the same code that works in VBA. I am not sure what all the naysaying is about. Every thread i have ever seen on running Com objects from Visual Studio says Don’t do it, It’s a Bad Idea. It seems to work fine.

as time goes by I may update this, but at this point –

Right click References in Solution Explorer, Add Reference, add the autocad type library.
To get the Autocad namespace to work across all modules, double click My Project in Solution Explorer and add Autocad to Imported Namespaces.

Get a book or study online the differences in syntax. They are pretty minor. The code editor is much improved. Arrays are a little simplified. Indexing is a little different, no static type. There is no variant type, but there is an object type that microsoft uses to read and write arrays to excel spreadsheets. (microsoft has a good one page link to connect to excel com objects HERE) Autodesk has no such single page that i can find, but here are some useful links.

http://help.autodesk.com/view/OARX/2019/ENU/?guid=GUID-BFFF308E-CC10-4C56-A81E-C15FB300EB70

http://help.autodesk.com/view/OARX/2019/FRA/?guid=GUID-C8C65D7A-EC3A-42D8-BF02-4B13C2EA1A4B

http://help.autodesk.com/view/OARX/2019/ENU/?guid=GUID-927E71C2-E515-438E-9D7A-246D97BEF93F

http://help.autodesk.com/view/OARX/2019/ENU/?guid=GUID-D1E1CE43-F42B-4D8E-9B42-FDA9D8CCB6B9

All methods to be capitalized. All arguments in parentheses. No set statements.
Sometimes you have to figure out how to get the namespace shortcuts to work. The error reporting in vs really helps.
The Try, Catch, End Try error system works more cleanly.
Many more tools to use with collections and array types.
There is a stricter approach to datatypes, a setting to relax it, but i have Option Strict On. this is where a book will help. 2012 books are cheap.

So far i have pasted in VBA code, made changes per notes above, and the same objects work with the same logic – lines, polylines, dimensions, blocks, ucs, text, selection sets.

Code below is for version 2018 (“Autocad.Application.22”)

Module Module_Connect_Acad

    Public acadApp As AcadApplication
    Public acaddoc As AcadDocument
    Public acadms As AcadModelSpace

    Public Sub Connect_acad()
        acadApp = Nothing
        Dim strProgId As String = "AutoCAD.Application.22"

        Try         '' Get a running instance of AutoCAD
            'acadApp = GetObject(, strProgId)
            acadApp = CType(GetObject(, strProgId), AcadApplication)

        Catch
            Try     '' Create a new instance of AutoCAD
                acadApp = CType(CreateObject(strProgId), AcadApplication)

            Catch ex As Exception
                MsgBox(ex.Message)
                Exit Sub
            End Try
        End Try

        acadApp.Visible = True  '' Display the application
        ' MsgBox("Now running " & acadApp.Name & " version " & acadApp.Version)

        'load whatever globals needed based on acadapp
        acaddoc = acadApp.ActiveDocument
        acadms = acadApp.ActiveDocument.ModelSpace
    End Sub

End Module