AfraLisp Blog

The AutoLisp/Visual Lisp/VBA Resource Website

AfraLisp Blog

Home Newsletter Utter Rubbish Coding Tips AutoCAD Tips Contact Downloads WAUN

Home. Page II. Page III.

Properties and Methods

The aim of this tutorial is not to describe the Properties and Methods of every AutoCAD Object, but rather to show you, first how to find the Properties and Methods available for an Object, and secondly to describe the usage of such Property or Method within Visual Lisp. Each Object within AutoCAD has numerous Properties and Methods which differ from Object to Object. To attempt to list each Property or Method for each Object is way beyond the scope of this tutorial.

First of all, let's have a look at defining a Property and a Method.

Visual Lisp Objects support properties and methods,  In Visual Lisp, an Object's data (settings or attributes) are called 'properties', while the various procedures that can operate on an Object are called it's 'methods'.

You can change an Object's characteristics by changing it's properties.
Consider a radio: One property of a radio is its volume. In Visual Lisp,
you might say that a radio has a 'Volume' property that you can adjust by
changing its value. Assume you can set the volume of a radio from 0 to 10.
If you could control a radio with Visual Lisp, you might write code in a
procedure that changes the value of the 'Volume' property from 3 to 5 to
make it play louder :

(vla-put-Volume Radio 5)

In addition to properties, objects have methods. Methods are part of objects
just as properties are. Generally, methods are actions you want to perform,
while properties are the attributes you set or retrieve. For example, you dial
a telephone to make a call. You might say that telephones have a 'Dial' method, and you could use this syntax to dial a seven digit number 3334444:

(vla-Dial Telephone 3334444)

Before you can start to change an Objects Properties or Methods, you need to know what Properties and Methods are available to the particular Object. There are a couple of ways of going about this. First we'll look at Properties.

Under AutoCAD Help, open "Visual Lisp and AutoLisp" and then "ActiveX and VBA Reference". Choose the "Objects" sub-section and from the list choose the Object whose Properties you would like list. Choose "Line".

As you can see, all the Properties applicable to the "Line" Object are listed.

Be careful though, as some of these Properties are "Read Only" and cannot be changed.
e.g. The "Angle" property is "Read Only." Think about it, if you changed the "ANGLE" Property, the Start or End point of the Line Object would have to change as well.

Click on any of the Property hyperlinks for further information.

Another way of finding an Objects properties is to use the Visual Lisp function (vlax-dump-object).

Open AutoCAD and then the Visual Lisp editor and type the following at the Console prompt :

_$ (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 01e42494>

_$ (setq apt (getpoint "Specify First Point: "))
(228.279 430.843 0.0)

_$ (setq pt (getpoint "Specify next point: " apt))
(503.866 538.358 0.0)

_$ (setq myline (vla-addline mspace (vlax-3d-point apt)(vlax-3d-point pt)))
#<VLA-OBJECT IAcadLine 01e84614>

_$ (vlax-dump-object myline)
; IAcadLine: AutoCAD Line Interface
; Property values:
;   Angle (RO) = 0.371971
;   Application (RO) = #<VLA-OBJECT IAcadApplication 00adc088>
;   Color = 256
;   Delta (RO) = (275.587 107.515 0.0)
;   Document (RO) = #<VLA-OBJECT IAcadDocument 00b94e14>
;   EndPoint = (503.866 538.358 0.0)
;   Handle (RO) = "958"
;   HasExtensionDictionary (RO) = 0
;   Hyperlinks (RO) = #<VLA-OBJECT IAcadHyperlinks 01e84564>
;   Layer = "7"
;   Length (RO) = 295.817
;   Linetype = "BYLAYER"
;   LinetypeScale = 1.0
;   Lineweight = -1
;   Normal = (0.0 0.0 1.0)
;   ObjectID (RO) = 25187840
;   ObjectName (RO) = "AcDbLine"
;   OwnerID (RO) = 25186496
;   PlotStyleName = "ByLayer"
;   StartPoint = (228.279 430.843 0.0)
;   Thickness = 0.0
;   Visible = -1
The (vlax-dump object) function lists all the available properties for a particular Object.
Note the (RO) after some of the Properties. This tells you that this Property is "Read Only".


Let's have a look at the Methods pertaining to an Object.
Under AutoCAD help, open "Visual Lisp and AutoLisp" and then "ActiveX and VBA Reference". Again, choose the "Objects" sub-section and from the list choose the Object whose Methods you would like list. Choose "Line".
 As you can see, all the Methods applicable to the "Line" Object are listed.

Click on the "Move" method.
The VBA Method for "Move" is displayed and the syntax is as follows :

object.Move Point1, Point2

Object : All Drawing Objects, AttributeRef. The object or objects this method applies to.

Point1 : Variant (three-element array of doubles); input-only. The 3D WCS coordinates specifying the first point of the move vector.

Point2 : Variant (three-element array of doubles); input-only. The 3D WCS coordinates specifying the second point of the move vector.

 

Let's move the line we've just drawn :

_$ (setq apt2 (getpoint "Specify Base Point: "))
(220.911 526.575 0.0)

_$ (setq pt2 (getpoint "Specify second point: " apt2))
(383.02 617.889 0.0)

_$ (vla-move myline (vlax-3d-point apt2)(vlax-3d-point pt2))
        

Now let's "dump" the Object, but this time we'll use the "T" flag to display the Objects Methods as well as it's Properties.

_$ (vlax-dump-object myline T)
; IAcadLine: AutoCAD Line Interface
; Property values:
;   Angle (RO) = 5.60729
;   Application (RO) = #<VLA-OBJECT IAcadApplication 00adc088>
;   Color = 256
;   Delta (RO) = (246.112 -197.356 0.0)
;   Document (RO) = #<VLA-OBJECT IAcadDocument 00b94e14>
;   EndPoint = (629.133 420.533 0.0)
;   Handle (RO) = "957"
;   HasExtensionDictionary (RO) = 0
;   Hyperlinks (RO) = #<VLA-OBJECT IAcadHyperlinks 01e84574>
;   Layer = "7"
;   Length (RO) = 315.469
;   Linetype = "BYLAYER"
;   LinetypeScale = 1.0
;   Lineweight = -1
;   Normal = (0.0 0.0 1.0)
;   ObjectID (RO) = 25187832
;   ObjectName (RO) = "AcDbLine"
;   OwnerID (RO) = 25186496
;   PlotStyleName = "ByLayer"
;   StartPoint = (383.02 617.889 0.0)
;   Thickness = 0.0
;   Visible = -1
; Methods supported:
;   ArrayPolar (3)
;   ArrayRectangular (6)
;   Copy ()
;   Delete ()
;   GetBoundingBox (2)
;   GetExtensionDictionary ()
;   GetXData (3)
;   Highlight (1)
;   IntersectWith (2)
;   Mirror (2)
;   Mirror3D (3)
;   Move (2)
;   Offset (1)
;   Rotate (2)
;   Rotate3D (3)
;   ScaleEntity (2)
;   SetXData (2)
;   TransformBy (1)
;   Update ()
"But, the syntax of the "Move" method you used in Visual Lisp, is different from the VBA syntax!! How do I know how to call the function in Visual Lisp?"

Don't worry, we'll be having a look at that on the next page.

Before we go there, here's a little application that will dump all Properties and Methods for selected Objects :

;coding starts here

(defun C:HaveaDump ( / ent)

  (vl-load-com)

    (while

        (setq ent (entsel))

        (vlax-dump-object (vlax-Ename->Vla-Object (car ent)) T)
    
     );while

   (princ)

);defun

(princ)
;coding ends here

On the next page we'll have a look at how we call Property and Method Functions. See you there.......
 
Home. Page II. Page III.
 
The AutoLisp/Visual Lisp/VBA Resource Website

Copyright 1999-Perpetuity by AfraLisp

All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage

The AutoLisp/Visual Lisp/VBA Resource Website