Add the AutoCAD 2004 Lib. and it works fine.
Here is all I did to make sure I could connect:
Imports AutoCAD
Public Class Form1
'********************************************'
'*********Varibles for AutoCAD**********'
'********************************************'
Public WithEvents AcadApp As AutoCAD.AcadApplication
Public WithEvents objDWG As AcadDocument
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SetAutoCADApplication()
End Sub
Private Sub SetAutoCADApplication()
On Error Resume Next
AcadApp = GetObject(, "AutoCAD.Application.16")
If Err.Number <> 0 Then
Err.Clear()
' Create a new session of AutoCAD 2004 using late binding
AcadApp = CreateObject("AutoCAD.Application.16")
If Err.Number <> 0 Then
MsgBox("Error, could not create a new AutoCAD session")
End
End If
End If
AcadApp.Visible = True
objDWG = AcadApp.ActiveDocument
End Sub
Private Sub DrawLine()
Dim objLine As AcadLine
Dim objCir As AcadCircle
Dim Point1 As Object
Dim Point2 As Object
On Error GoTo Err_Control
objDWG.Utility.CreateTypedArray(Point1, vbDouble, 20, 20, 0)
objDWG.Utility.CreateTypedArray(Point2, vbDouble, 0, 0, 0)
objLine = objDWG.ModelSpace.AddLine(Point1, Point2)
objCir = objDWG.ModelSpace.AddCircle(Point1, 5)
objLine.Layer = "New"
objCir.Layer = "New"
Exit_Here:
Exit Sub
Err_Control:
Select Case Err.Number
Case -2145386476
'Layer not found
objDWG.Layers.Add("New")
Resume
Case Else
Debug.Print(Err.Number & ": " & Err.Description)
Resume Exit_Here
End Select
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
DrawLine()
End Sub
Private Sub AcadApp_NewDrawing() Handles AcadApp.NewDrawing
objDWG = AcadApp.ActiveDocument
End Sub
End Class