VB Programming Guidelines

AutoCAD Land Desktop ActiveX & VBA

VB Programming Guidelines

 

In general, all of the guidelines from the VBA section also apply to VB. This section includes some additional information that is specific to developing stand-alone (out-of-process) applications using Visual Basic.

Connecting to AutoCAD Land Desktop

Visual Basic provides a function called GetObject to get a reference to a currently active instance of an ActiveX object of the specified type. Since a compiled VB application is in a different process than AutoCAD Land Desktop, you must "connect" to the application object:

Dim acad As AcadApplication

Set acad = GetObject(, "AutoCAD.Application")

Next, you use the AcadApplication.GetInterfaceObject method to get an instance of the AutoCAD Land Desktop application object:

Dim app As AeccApplication

Set app = acad.GetInterfaceObject("Aecc.Application")

You might want to declare these variables as Public at the module level so that they are available to all procedures in all modules.

For Next Loops

When using a For Next loop to iterate through an object collection use "EXIT FOR" if you need to exit the loop befor conclusion. If a "GOTO" is used to exit the loop the reference count to the object is not cleaned and will create an error condition.

Quiescent State and ActiveX calls

When AutoCAD is at the command line prompt, it is in a quiescent state. When AutoCAD has completed processing the last command and there are no pending commands, it is in a state that AutoCAD can process an ActiveX call.

Be aware that if AutoCAD is busy when your application tries to invoke an ActiveX property or method, AutoCAD may display a modal dialog indicating that the ActiveX request was not handled. You are then prompted to retry the request.

To prevent this situation, your application should use the AcadApplication.GetAcadState method to determine if AutoCAD is busy. This method returns an AcadState object, which is a transient object used to check for AutoCAD quiescence from out-of-process applications.