Properties and Methods - Page II.
How to Call a Visual Lisp Function
Right, you've identified the Visual Lisp
Property or Method that you need, but you still need to determine how to
call the function. You need to know the arguments to specify and the data
type of those arguments.
Let's look at Properties first.
The syntax for the Layer Property in VBA is
as follows :
object.Layer or object.property
object : All Drawing objects, AttributeRef, Group. The object or
objects this property applies to.
Layer : String; read-write (write-only for the Group object). The name
of the layer.
Remarks
All entities have an associated layer. The document always contains at
least one layer (layer 0). As with linetypes, you can specify a layer for
an entity. If you don’t specify a layer, the current active layer is
used for a new entity. If a layer is specified for an entity, the current
active layer is ignored. Use the ActiveLayer property to set or query the
current active layer.
Each layer has associated properties that can be set and queried through
the Layer object.
In VBA you would use
Oldlayer = object.Layer to
retrieve the Layer Name, and
object.Layer = "2" to
change the Layer Name.
Visual Lisp provides functions for reading
and updating Object Properties.
Functions that read Object Properties are named with a vla-get
prefix and require the following syntax :
(vla-get-property object)
For example, "vla-get-layer
object" returns the Layer
the Object is on.
Enter this in the Visual Lisp Console :
_$ (vl-load-com)
_$ (setq acadDocument (vla-get-activedocument (vlax-get-acad-object)))
#<VLA-OBJECT IAcadDocument 00b94e14>
_$ (setq mspace (vla-get-modelspace acadDocument))
#<VLA-OBJECT IAcadModelSpace 01e42444>
_$ (setq apt (getpoint "Specify First Point: "))
(307.86 539.809 0.0)
_$ (setq pt (getpoint "Specify next point: " apt))
(738.188 479.426 0.0)
_$ (setq myline (vla-addline mspace (vlax-3d-point apt)(vlax-3d-point
pt)))
#<VLA-OBJECT IAcadLine 01e81de4>
_$ (setq oldlayer (vla-get-layer myline))
"7"
The variable "oldLayer"
now contains the Layer name of your Line Object.
Functions that update Properties are
prefixed with vla-put and use the following syntax :
(vla-put-property object new-value)
For example, "vla-put-layer
object new-value" changes
the layer of the Object.
Enter this at the Console prompt :
_$ (vla-put-layer myline "4")
nil
Your line will have now changed to Layer
"4".
Let's have a look at Methods now.
The syntax for the "Offset" Method in VBA is as follows :
RetVal = object.Offset(Distance) or Return
Value = object.Method (arguments)
Object : Arc, Circle, Ellipse, Line, LightweightPolyline, Polyline,
Spline, XLine. The object or objects this method applies to.
Distance : Double; input-only. The distance to offset the object.
The offset can be a positive or negative number, but it cannot equal zero.
If the offset is negative, this is interpreted as being an offset to make
a "smaller" curve (that is, for an arc it would offset to a
radius that is "Distance less" than the starting curve's
radius). If "smaller" has no meaning, then it would offset in
the direction of smaller X, Y, and Z WCS coordinates.
RetVal : Variant (array of objects). An array of the newly created objects
resulting from the offset.
In VBA you would use
offsetObj = object.offset(15.5)
to Offset an Object.
The syntax definitions used in the "ActiveX and VBA
Reference" were designed for Visual Basic Users. Consider the VBA
Offset Method :
returnvalue = object.Method (arguments)
returnvalue = object.Offset(Distance) or
using the names in our example
offLine = myline.Offset(15.5)
The syntax for the same operation in Visual
Lisp is :
(setq returnvalue (vla-method object
argument)) or using our names
(setq offLine (vla-offset myline 15.5))
Different Objects have different Methods but the
same principle applies.
Type this at the Console prompt :
_$ (setq offLine (vla-offset myline 15.5))
#<variant 8201 ...>
The variable "offLine", now
contains the data for your newly created line in the form of a variant
array.
So to recap :
- vla-get- functions correspond to every
ActiveX Property, enabling you to retrieve the value of that Property
(for example, vla-get-Color obtains an Object's Color Property.
- vla-put- functions correspond to every
Property, enabling you to update the value of the Property (for
example, vla-put-Color updates an Objects Color Property.
- vla- functions correspond to every ActiveX
Method. Use these functions to invoke the Method (for example, vla-addCircle
invokes the addCircle Method.
Visual Lisp also adds a set of ActiveX-related
functions whose names are prefixed with vlax-. These are more
general ActiveX functions, each of which can be applied to numerous
Methods, Properties or Objects. For example, with the vlax-get-property
function, you can obtain any Property of any ActiveX Object.
On the next page we'll have a look at how we can
determine whether an Object is available for updating and whether a Method
or a Property applies to an Object.
|