About Determining If an ActiveX Method or Property Applies to an Object (AutoLISP/ActiveX)

Trying to use a method or reference a property that does not apply to a specified object results in an error.

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

When you are not sure what which method or property applies to an object, use the vlax-method-applicable-p and vlax-property-available-p functions. These functions return T if the method or property is available for the object, and nil if it is not.

The syntax for vlax-method-applicable-p is:

(vlax-method-applicable-p object method)

The following checks to see if the Copy method can be applied to the object referenced by WhatsMyLine:

(vlax-method-applicable-p WhatsMyLine "Copy")
T

The following determines whether or not the AddBox method can be applied to the object:

(vlax-method-applicable-p WhatsMyLine "AddBox")
nil

For vlax-property-available-p, the syntax is:

(vlax-property-available-p object property [T])

For example, the following determines if Color and Center are properties of WhatsMyLine:

(vlax-property-available-p WhatsMyLine "Color")
T
(vlax-property-available-p WhatsMyLine "Center")
nil

Supplying the optional T argument to vlax-property-available-p changes the results that are returned. If you supply this argument, the function returns T only if the object has the property and the property can be modified. If the object has no such property or the property is read-only, vlax-property-available-p returns nil.

For example, an ellipse contains an Area property, but you cannot update it. If you check the property without specifying the optional argument, the result is T:

(vlax-property-available-p myEllipse "Area")
T

If you supply the optional argument, the result is nil:

(vlax-property-available-p myEllipse "Area" T)
nil