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

Trying to use a method that does not apply to the specified object will result in an error. Trying to reference a property that does not apply to an object also results in an error. In instances where you are not sure what applies, use the vlax-method-applicable-p and vlax-property-available-p functions to test the objects. 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 command 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 command 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 commands determine 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 meaning of the test. 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