Using ActiveX Objects with AutoLISP

AutoCAD AutoLISP & Visual LISP

 
Using ActiveX Objects with AutoLISP
 
 
 

ActiveX Automation is a way to work programmatically with the contents of an AutoCAD® drawing. In many instances, ActiveX works faster than traditional AutoLISP functions in manipulating AutoCAD drawing objects.

The ActiveX programming interface is usable in a number of languages and environments. When you work with ActiveX objects in AutoLISP, you work with the same object model, properties, and methods that can be manipulated from other programming environments.

Objects are the main building blocks of an ActiveX application. In some ways, you are already familiar with this notion. For example, AutoCAD drawing items such as lines, arcs, polylines, and circles have long been referred to as objects. But in the ActiveX schema, the following AutoCAD components are also represented as objects:

  • Style settings, such as linetypes and dimension styles
  • Organizational structures, such as layers, groups, and blocks
  • The drawing display, such as the view and viewport
  • The drawing's model space and paper space

Even the drawing and the AutoCAD application itself are considered objects.

NoteTo access drawing properties such as Title, Subject, Author, and Keywords, the IAcadSummaryInfo interface, accessible as a property of the Document object in the AutoCAD object model, must be used. For more information, see Accessing Drawing Properties.

ActiveX includes much of the functionality provided by standard AutoLISP functions such as entget, entmod, and setvar. Compared to these functions, ActiveX runs faster and provides easier access to object properties. For example, to access the radius of a circle with standard AutoLISP functions, you must use entget to obtain a list of entities and assoc to find the property you want. You must also know the code number (DXF key value) associated with that property to obtain it with assoc, as shown in the following example:

(setq radius (cdr (assoc 40 (entget circle-entity))))

With an ActiveX function, you simply ask for the radius of a circle as follows:

(setq radius (vla-get-radius circle-object))