AfraLisp Blog

The AutoLisp/Visual Lisp/VBA Resource Website

AfraLisp Blog

Home Newsletter Utter Rubbish Coding Tips AutoCAD Tips Contact Downloads WAUN

Home. Page I. Page II.

The Beginning - Page III.

Before we can create entities, or Objects, within AutoCAD, we need to decide "where" we want to draw, Model Space or Paper Space. And to do that we need to create a reference to the area in which we would like to draw.
Remember our filing cabinet?  The Application Object was our drawer, the Document Object was our folder, and now the Model Space Object will be our piece of paper. Let's have a look at the Model Space Object :

_$ (setq modelSpace (vla-get-ModelSpace (vla-get-ActiveDocument (vlax-get-Acad-Object))))
#<VLA-OBJECT IAcadModelSpace 018ade24>

Now run a dump on the modelSpace Object :

_$ (vlax-dump-object modelSpace T)
; IAcadModelSpace: A special Block object containing all model space entities
; Property values:
; Application (RO) = #<VLA-OBJECT IAcadApplication 00adc088>
; Count (RO) = 0
; Document (RO) = #<VLA-OBJECT IAcadDocument 00ee0f84>
; Handle (RO) = "18"
; HasExtensionDictionary (RO) = 0
; IsLayout (RO) = -1
; IsXRef (RO) = 0
; Layout (RO) = #<VLA-OBJECT IAcadLayout 018ad934>
; Name = "*MODEL_SPACE"
; ObjectID (RO) = 21871808
; ObjectName (RO) = "AcDbBlockTableRecord"
; Origin = (0.0 0.0 0.0)
; OwnerID (RO) = 21871624
; XRefDatabase (RO) = AutoCAD.Application: No database
; Methods supported:
; Add3DFace (4)
; Add3DMesh (3)
; Add3DPoly (1)
; AddArc (4)
; AddAttribute (6)
; AddBox (4)
; AddCircle (2)
; AddCone (3)
; AddCustomObject (1)
; AddCylinder (3)
; AddDim3PointAngular (4)
; AddDimAligned (3)
; AddDimAngular (4)
; AddDimDiametric (3)
; AddDimOrdinate (3)
; AddDimRadial (3)
; AddDimRotated (4)
; AddEllipse (3)
; AddEllipticalCone (4)
; AddEllipticalCylinder (4)
; AddExtrudedSolid (3)
; AddExtrudedSolidAlongPath (2)
; AddHatch (3)
; AddLeader (3)
; AddLightWeightPolyline (1)
; AddLine (2)
; AddMInsertBlock (10)
; AddMLine (1)
; AddMText (3)
; AddPoint (1)
; AddPolyfaceMesh (2)
; AddPolyline (1)
; AddRaster (4)
; AddRay (2)
; AddRegion (1)
; AddRevolvedSolid (4)
; AddShape (4)
; AddSolid (4)
; AddSphere (2)
; AddSpline (3)
; AddText (3)
; AddTolerance (3)
; AddTorus (3)
; AddTrace (1)
; AddWedge (4)
; AddXline (2)
; AttachExternalReference (8)
; Bind (1)
; Delete ()
; Detach ()
; GetExtensionDictionary ()
; GetXData (3)
; InsertBlock (6)
; Item (1)
; Reload ()
; SetXData (2)
; Unload ()
T

Interesting hey? Now let's draw something. Enter this coding :

(setq pt1 (getpoint "\nSpecify First Point : "))
(while (setq pt2 (getpoint "\nSpecify next point : " pt1))
(vla-addline modelSpace (vlax-3d-point pt1) (vlax-3d-point pt2))
(setq pt1 pt2)
)
(428.748 578.851 0.0)
(524.783 509.712 0.0)

At last, we've finally drawn something. Now type this :

_$ (setq pt1 (getpoint "\nSpecify First Point : "))
(setq pt2 (getpoint "\nSpecify next point : " pt1))
(setq ourLine (vla-addline modelSpace (vlax-3d-point pt1) (vlax-3d-point pt2)))
(922.321 585.542 0.0)
(1016.12 300.064 0.0)
#<VLA-OBJECT IAcadLine 018ab094>

Did you notice the (setq ourLine statement? This sets a reference to our Line Object. Let's run a dump on that :

_$ (vlax-dump-object ourLine T)
; IAcadLine: AutoCAD Line Interface
; Property values:
; Angle (RO) = 5.02985
; Application (RO) = #<VLA-OBJECT IAcadApplication 00adc088>
; Color = 256
; Delta (RO) = (93.8012 -285.479 0.0)
; Document (RO) = #<VLA-OBJECT IAcadDocument 00ee0f84>
; EndPoint = (1016.12 300.064 0.0)
; Handle (RO) = "95D"
; HasExtensionDictionary (RO) = 0
; Hyperlinks (RO) = #<VLA-OBJECT IAcadHyperlinks 018aa2b4>
; Layer = "7"
; Length (RO) = 300.494
; Linetype = "BYLAYER"
; LinetypeScale = 1.0
; Lineweight = -1
; Normal = (0.0 0.0 1.0)
; ObjectID (RO) = 21873192
; ObjectName (RO) = "AcDbLine"
; OwnerID (RO) = 21871808
; PlotStyleName = "ByLayer"
; StartPoint = (922.321 585.542 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 ()
T


We now have a list of all the Properties and Methods of our Line Object. Let's change some of it's properties :

Let's change it's Layer:
_$ (vla-put-layer ourLine 2)
nil


And now it's color :
_$ (vla-put-color ourLine 6)
nil

Let's delete our line :

_$ (entdel (vlax-vla-object->ename ourLine))
<Entity name: 14dc1f8>

Did you notice how we used a standard AutoLisp command (entdel) to delete the line? But before we could do that, we had to convert the VLisp Object Reference to an AutoLisp Entity Name.

You are probably wondering why we don't just use the AutoLisp (command) function to draw or change entities. If you use reactor call-back functions, you are not allowed to use the (command) function.


If terms such as Objects, Properties, Methods and Events sound double Dutch to you, have a read through An Introduction to VBA. This is written for VBA but much of the same terminology applies to Visual Lisp.

Well, I hope this has given you an insight into the use of Visual Lisp? Don't worry, we'll be looking a lot closer at all aspects of Visual Lisp in future Tutorials. This is just to get you started and give you a taste of what's to come.

Home. Page I. Page II.
 
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