Share
 
 

About Obtaining and Setting an Object’s Property (AutoLISP/ActiveX)

You can access an object’s properties using the wrapper functions that are created by importing a type library or directly with the use of the vlax-get-property and vlax-put-property functions.

Note: ActiveX support in AutoLISP is limited to Windows only.

After loading the ActiveX support functions with vl-load-com, you can use the vla-get- and vla-put- functions to get and set the values of an object’s property.

The vla-get-propertyname function returns the property of an object, while vla-put-propertyname function assigns a value to an object’s property. These functions require the following arguments:

  • A VLA-object identifying the object whose property you are interested in
  • A value to assign to the property when using the vla-put-propertyname function

For example, the following returns the AutoCAD application object's ActiveDocument property:

(vla-get-ActiveDocument (vlax-get-acad-object))
#<VLA-OBJECT IAcadDocument 00302a18>

The functions that start with vla- are wrapper functions for the AutoCAD ActiveX type library, but the names of the wrapper functions for other type libraries will vary based on the prefixes you use.

Note: AutoCAD LT does not support the ability to import or work with third-party ActiveX libraries.

In addition to the wrapper functions, you can use the vlax-get-property function to return the value of an object's property, while the vlax-put-property function assigns a value to an object’s property. These functions require the following arguments:

  • A VLA-object identifying the object whose property you are interested in
  • A symbol or string naming the property to be retrieved
  • A value to assign to the property when using the vlax-put-propertyname function

You can use vlax-get-property (and vlax-put-property) even if a wrapper function is available.

For example, the following returns the AutoCAD application object's ActiveDocument property:

(vlax-get-property (vlax-get-acad-object) 'ActiveDocument)
#<VLA-OBJECT IAcadDocument 00302a18>

Using Constants

Sometimes you can use pre-defined constants to update an object's property. For example, to set the fill color of a circle to green, you can use the constant acGreen instead of specifying a numeric index value:

(vla-put-color myCircle acGreen)

The ActiveX Reference lists any predefined constants under the entry describing the property. You can use these constants in AutoLISP ActiveX function calls.

Updating an Object

Changing an object's property may not immediately affect the display of the object in the AutoCAD drawing. AutoCAD delays property changes to allow you to change more than one property at a time.

If you need to update the drawing window explicitly, issue the vla-update function:

(vla-update object)

Working with Imported Libraries (AutoCAD for Windows Only)

An ActiveX type library can be imported. Upon importing a library, the names of the wrapper functions can optionally prefixed. After importing a library, you can see which wrapper functions are available to you using the Apropos window. However, not all properties, method, and constants in an imported type library are wrapped.

For example, there is no wrapper function available to obtain the CommandBars property of the Microsoft Word application object, but the following statement achieves this:

(setq ComBars (vlax-get-property msw 'CommandBars))
#<VLA-OBJECT CommandBars 0016763c>

Was this information helpful?