21 | 08 | 2017

Set AutoCad Reference

If you are familiar with AutoCad VBA then its a small step to start programming  Visual Basic 6.0. You only need to set the reference to the AutoCad type library: 
In Visual Basic 6.0 goto PROJECT > REFERENCE and check the checkbox of the AutoCad Type Library as shown below.

AutoCad Reference

With this done VB 6.0 is now equiped with the same library as AutoCad VBA. Now it's possible to create the Thisdrawing statement from which we can start giving commands to AutoCad 
The code below sets up the connection and we check if AutoCad is open and if not we open it ourselves. 

Public ThisDrawing As AcadDocument
Public Sub Connect2AutoCad()
'*** Code from VisibleVisual.com ********
Dim Acad As AcadApplication
On Error Resume Next
'Check if AutoCad is open
Set Acad = GetObject(, "AutoCAD.Application")
If Err Then
MsgBox "Autocad Application is Not Open"
Exit Sub
'Attempt to open AutoCad
Set Acad = CreateObject("AutoCAD.Application")
'AutoCAD isn't available
If Err Then
MsgBox "Can't start AutoCAD!", vbExclamation, "Error loading AutoCAD"
End If
End If
Set ThisDrawing = objAcad.ActiveDocument
Acad.Visible = True
End Sub

Now you can use the Thisdrawing statement in Visual Basic 6.0 the same as you would have done in VBA


Sign up now and upload your code to the website.

Help us to continue.....
Articles View Hits
Latest Articles