About Invoking an Object’s Method (AutoLISP/ActiveX)

 
 
 

You can invoke an object’s method using a wrapper function that is created by importing a type library or directly with the use of the vlax-invoke-method function.

NoteActiveX support in AutoLISP is limited to Windows only.

After loading the ActiveX support functions with vl-load-com, you can use the vla- function to invoke an object’s method.

The vla-methodname function requires the following arguments:

For example, the following adds a Circle object to the current drawing’s model space:

(setq MSpace (vla-get-ModelSpace (vla-get-ActiveDocument (vlax-get-acad-object))))
#<VLA-OBJECT IAcadModelSpace 0000000030434638>

(vla-AddCircle MSpace (vlax-3d-point '(5.0 5.0 0.0)) 3)
#<VLA-OBJECT IAcadCircle 00000000303b2698>

The functions that start with vla- are wrapper functions for the AutoCAD type library, but the names of the wrapper functions for other type libraries will vary based on the prefixes you use. Importing a type library is ideal so you can see which functions are available to you using the Apropos window. However, not all properties, method, and constants in an imported type library are wrapped.

The vlax-invoke-method function executes an object’s method. The function requires the following arguments:

You can use vlax-invoke-method even if a wrapper function is available for the task.

For example, the following adds a Circle object to the current drawing’s model space:

(setq MSpace (vlax-get-property (vlax-get-property (vlax-get-acad-object) 'ActiveDocument) 'ModelSpace))
#<VLA-OBJECT IAcadModelSpace 0000000030434638>

(vlax-invoke-method MSpace 'AddCircle (vlax-3d-point '(5.0 5.0 0.0)) 3)
#<VLA-OBJECT IAcadCircle 00000000303b2698>