Properties and Methods - Page III.
Determining Whether an Object is
Available for Updating
If other applications are working with any
AutoCAD Objects at the same time as your program, those Objects may not be
accessible. This is especially important to lookout for if your
application includes reactors, because reactors execute code segments in
response to external events that cannot be predicted in advance. Even a
simple thing such as a locked Layer can prevent you from changing an
Objects Properties.
Visual Lisp provides the following
functions to test the accessibility of an Object before trying to use the
Object :
- vlax-read-enabled-p Tests whether
you can read an Object.
- vlax-write-enabled-p Determines
whether you can modify an Objects Properties.
- vlax-erased-p Checks to see if an
Object has been erased. Erased Objects may still exist in the drawing
database.
All these test functions return T if
true, and nil if false.
Let's test them out. Draw a line anywhere in AutoCAD then enter this at
the Console prompt :
_$ (vl-load-com)
_$ (setq ent (entsel))
(<Entity name: 17e39f8> (434.601 389.588 0.0))
_$ (setq myLine (vlax-Ename->Vla-Object
(car ent)))
#<VLA-OBJECT IAcadLine 01e81f84>
Determine whether the line is readable :
_$ (vlax-read-enabled-p myLine)
T
Determine whether the line is modifiable :
_$ (vlax-write-enabled-p myLine)
T
See if the line has been erased :
_$ (vlax-erased-p myLine)
nil
Erase the line :
_$ (vla-delete myLine)
nil
See if the line is still readable :
_$ (vlax-read-enabled-p myLine)
nil
Check to confirm that the object has been deleted :
_$ (vlax-erased-p myLine)
T
Determining If a Method or Property Applies to an
Object
Trying to use a Method that does not apply to a
specified Object will result in an error. The same goes for trying to
reference a Property that does not apply to an Object. This will also
result in an error. In instances where you are not sure what applies, use
the vlax-method-applicable-p and the vlax-property-available-p
functions.
These functions return T if the Method or Property is available for
the Object, and nil if 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 an Object :
_$ (vlax-method-applicable-p myLine
"Copy")
T
The following command determines if the "addBox"
Method can be applied to an Object :
_$ (vlax-method-applicable-p myLine
"addBox")
nil
For vlax-property-available-p
the syntax is :
(vlax-property-available-p object
property [T])
The following commands determine if Color and
Center are properties of the myLine Object :
(vlax-property-available-p myLine
"Color")
T
(vlax-property-available-p myLine "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, a Circle 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
myCircle "area")
T
If you supply the optional argument, the result is
nil :
(vlax-property-available-p
myCircle "area" T)
nil
Well, that's it with Methods and
Properties. Time for me to pour myself a nice long, cold beer and retire
to the garden and sit in the sun. The advantages of living in Africa. Eat
your heart out............
Oh, by the way, my Mum has got a great Method of cooking Tripe and Onion's
if anybody is interested!!
|