How VBA Is Implemented in AutoCAD
 
 
 

VBA sends messages to AutoCAD by the AutoCAD ActiveX Automation interface. AutoCAD VBA permits the VBA environment to run simultaneously with AutoCAD and provides programmatic control of AutoCAD through the ActiveX Automation interface. This coupling of AutoCAD, ActiveX Automation, and VBA provides an extremely powerful interface not only for manipulating AutoCAD objects, but for sending data to or retrieving data from other applications.

There are three fundamental elements that define ActiveX and VBA programming in AutoCAD.The first is AutoCAD itself, which has a rich set of objects that encapsulates AutoCAD entities, data, and commands. Because AutoCAD was designed as an open-architecture application with multiple levels of interface, familiarity with AutoCAD programmability is highly desirable in order to use VBA effectively. If you've used AutoLISP to control AutoCAD programmatically, you already have a good understanding of the AutoCAD facilities. However, you will find the VBA object-based approach to be quite different from that of AutoLISP.

The second element is the AutoCAD ActiveX Automation interface, which establishes messages (communication) with AutoCAD objects.Programming in VBA requires a fundamental understanding of ActiveX Automation. A description of the AutoCAD ActiveX Automation interface can be found in the ActiveX and VBA Reference. Even the experienced VB programmer will find the AutoCAD ActiveX Automation interface invaluable for understanding and developing AutoCAD VBA applications.

The third element is the VBA programming environment, which has its own set of objects, keywords, constants, and so forth that provides program flow, control, debugging, and execution. Microsoft's own extensive Help for VBA is included with the AutoCAD VBA Help and is accessible from the VBA IDE by any of the following methods: