Author Topic: Script to determine levelness  (Read 2395 times)

0 Members and 1 Guest are viewing this topic.

guybor

  • Guest
Script to determine levelness
« on: June 05, 2010, 10:31:23 AM »
I am very good with computers and software....just not autocad.  I know VB and VBA so I considered trying to tackle this project in VBA, but with Autocad deciding that VBA is dead I decided to not waste the time.  So I'm asking for help here.

We fabricate granite countertops and do digital measurements with a machine.  In the DXF that it creates I can generate a layer of points that are the top of the cabinets.  I also generate a 3 point layer that is the plane of the countertops. (defaults to Z=0...so I assume that is good)  What I'm looking for is a lisp script (or other way in cad) to look at each of those points and determine how far off of the 0 plane the point is and either create a csv file or a text file or a table in the drawing showing the X, Y and Z value of the point.  The "levelness" plane is always on the same layer from drawing to drawing. (I don't know what the exact layer name is called off the top of my head)

Is this easily doable?

Thanks in advance.
Guy

uncoolperson

  • Guest
Re: Script to determine levelness
« Reply #1 on: June 05, 2010, 10:39:55 AM »
you could make a list of the point x y z and sort them by the z and output to a text file.

hermanm

  • Guest
Re: Script to determine levelness
« Reply #2 on: June 05, 2010, 11:28:53 AM »
Jump in, and welcome to  the LISP forum.:)

Actually, Microsoft decided several years ago to euthanize VBA, and vendors such as Adesk have little choice but to conform to Microsoft's policy.

Points have x,y,z coordinates, so if the reference plane has z=0, determining how far a point is from this plane reduces to examining the z coordinate.

You should first become familiar with (entget) function.
Classic AutoLISP via (entget) & (entmod) are intimately related to DXF.
So, the DXF reference is your friend. DXF group codes are identical to those returned by (entget).

For example, the DXF reference for a POINT entity gives:

(partial listing)

100
 Subclass marker (AcDbPoint)
 
10
 Point location (in WCS)

DXF: X value; APP: 3D point
 
20, 30
 DXF: Y and Z values of point location (in WCS)

If you create a POINT entity:

Command: point

Current point modes:  PDMODE=34  PDSIZE=0'-0 1/2"
Specify a point:

Then query the entity via AutoLISP:

Command: (entget(entlast))
((-1 . <Entity name: 7c7c7280>) (0 . "POINT") (330 . <Entity name: 78760e60>)
(5 . "15E38") (100 . "AcDbEntity") (67 . 1) (410 . "Mezzanine Plan") (8 .
"ANNOBJ") (100 . "AcDbPoint") (10 7.51955 1.38385 0.0) (210 0.0 0.0 1.0) (50 .
0.0))

You will see that:

(10 7.51955 1.38385 0.0)

corresponds to the POINT's coordinates

Command: list

Select objects: last
1 found

Select objects:

                  POINT     Layer: "ANNOBJ"
                            Space: Paper space
                           Layout: Mezzanine Plan
                   Handle = 15e38
                at point, X=0'-7 33/64"  Y=0'-1 25/64"  Z=    0'-0"

You can also convert enames to vla-objects and manipulate them using the object model with which you are familiar:

Command: (setq obj (vlax-ename->vla-object (entlast)))
#<VLA-OBJECT IAcadPoint 1d4b1a84>

Command: (load "dump")
DUMP

Command: (dump obj)
; IAcadPoint: AutoCAD Point Interface
; Property values:
;   Application (RO) = #<VLA-OBJECT IAcadApplication 00d74d3c>
;   Coordinates = (7.51955 1.38385 0.0)
;   Document (RO) = #<VLA-OBJECT IAcadDocument 01e4c750>
;   Handle (RO) = "15E38"
;   HasExtensionDictionary (RO) = 0
;   Hyperlinks (RO) = #<VLA-OBJECT IAcadHyperlinks 2036c774>
;   Layer = "ANNOBJ"
;   Linetype = "BYLAYER"
;   LinetypeScale = 1.0
;   Lineweight = -1
;   Material = "ByLayer"
;   Normal = (0.0 0.0 1.0)
;   ObjectID (RO) = 2088530560
;   ObjectName (RO) = "AcDbPoint"
;   OwnerID (RO) = 2021002848
;   PlotStyleName = "ByLayer"
;   Thickness = 0.0
;   TrueColor = #<VLA-OBJECT IAcadAcCmColor 22934730>
;   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)
;   Rotate (2)
;   Rotate3D (3)
;   ScaleEntity (2)
;   SetXData (2)
;   TransformBy (1)
;   Update ()
nil

Command: (vlax-safearray->list (vlax-variant-value (vlax-get-property obj
'Coordinates)))
(7.51955 1.38385 0.0)

HTH
 



CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Script to determine levelness
« Reply #3 on: June 05, 2010, 03:28:16 PM »
This should get you the values. It just sends them to the command line for viewing.
The output of that data can be sent to a table or csv file too.
Code: [Select]
(defun c:test (/ fuzz ss MyLayer i ename elst)
  (setq MyLayer "0")                    ; only on layer zero
  (setq fuzz 0.125)                     ; Z = zero +- this value
  (setq ss (ssget "_X"                  ; All objects, but filter for the following
                  (list '(0 . "point")  ; only POINT objects
                        (cons 8 MyLayer) ; only on this layer
                        '(-4 . "*,*,>")
                        (list 10 0 0 (- fuzz)) ; with a Z valve of minus fuzz
                        '(-4 . "*,*,<")
                        (list 10 0 0 fuzz) ; with a Z valve of plus fuzz
                        (cons 410 (getvar "ctab")) ; objects in current space only
                  )
           )
  )
  (if ss ; entities that fit the filter
    (progn
       (setq i -1)
       (while (setq ename (ssname ss (setq i (1+ i))))
         (setq elst (entget ename))
         ;;  ignore Z of zero
         (if (not (zerop (caddr (setq xyz (cdr (assoc 10 elst))))))
           (print xyz)
         )
       )
    )
  )
  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Script to determine levelness
« Reply #4 on: June 05, 2010, 03:31:27 PM »
Oh, and welcome to the Swamp.  :-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

guybor

  • Guest
Re: Script to determine levelness
« Reply #5 on: June 05, 2010, 09:09:03 PM »
Oh, and welcome to the Swamp.  :-)

Thanks.

Any recommendation for a book to learn lisp (or should I be looking at learning something else for CAD)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Script to determine levelness
« Reply #6 on: June 05, 2010, 09:47:52 PM »
Read through this thread & see the last few posts.
http://www.theswamp.org/index.php?topic=24700.0
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.