AutoCAD from VB, error type

AutoCAD from VB, error type

Anonymous
Not applicable
285 Views
1 Reply
Message 1 of 2

AutoCAD from VB, error type

Anonymous
Not applicable
Hello..

I want to develop an application that runs inside AutoCAD, but i want to launch this application from an icon in Windows desktop. this icon would launch AutoCAD and my application, that is a VB Form. I've found this code for launch autoCAD in VB6, but it doesn't work. When i execute the program i get an error "Unknown type". I've reference the Autocad Common Libray file. But it seems to be needed another file, which file i've to reference?

This is the code i've found:

Public Sub Connect(Optional AcVisiblity As Boolean = True)

'Establish a connection to Autocad, Create one
'if none exists
Dim oAcadApp As acadapplication

Dim i As Integer: i = 0
On Error Resume Next
Set oAcadApp = GetObject(, "AutoCAD.Application.15")
If Err Then
Err.Clear
Restart:
Set oAcadApp = CreateObject("AutoCAD.Application.15")
If Err.Number = 91 Then
Err.Clear
If i = 3 Then
Exit Sub
Else
GoTo Restart
i = i + 1
End If
Else
Err.Clear
End If
End If

'Set the Visibility option
oAcadApp.Visible = AcVisiblity

'Raise Event when connection is first completed
RaiseEvent ConnectionOpened

End Sub
0 Likes
286 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable
This would work much better for you. Public Function LoadAutoCAD(oApp As AcadApplication) As Boolean On Error Resume Next 'try to get running instant of AutoCAD Set oApp = GetObject(, "AutoCAD.Application") If Err Then Err.Clear Set oApp = CreateObject("AutoCAD.Application") 'exit function, no AutoCAD available If Err Then Exit Function End If 'AutoCAD instant open, make it visible oApp.Visible = True 'return True that AutoCAD was opened successfully LoadAutoCAD = True End Function "alkimium" wrote in message news:22100390.1096474145386.JavaMail.jive@jiveforum2.autodesk.com... > Hello.. > > I want to develop an application that runs inside AutoCAD, but i want to launch this application from an icon in Windows desktop. this icon would launch AutoCAD and my application, that is a VB Form. I've found this code for launch autoCAD in VB6, but it doesn't work. When i execute the program i get an error "Unknown type". I've reference the Autocad Common Libray file. But it seems to be needed another file, which file i've to reference? > > This is the code i've found: > > Public Sub Connect(Optional AcVisiblity As Boolean = True) > > 'Establish a connection to Autocad, Create one > 'if none exists > Dim oAcadApp As acadapplication > > Dim i As Integer: i = 0 > On Error Resume Next > Set oAcadApp = GetObject(, "AutoCAD.Application.15") > If Err Then > Err.Clear > Restart: > Set oAcadApp = CreateObject("AutoCAD.Application.15") > If Err.Number = 91 Then > Err.Clear > If i = 3 Then > Exit Sub > Else > GoTo Restart > i = i + 1 > End If > Else > Err.Clear > End If > End If > > 'Set the Visibility option > oAcadApp.Visible = AcVisiblity > > 'Raise Event when connection is first completed > RaiseEvent ConnectionOpened > > End Sub
0 Likes