Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Polyline 'Z' Values not being returned by vla-get-coordinates....

7 REPLIES 7
Reply
Message 1 of 8
petervose
1629 Views, 7 Replies

Polyline 'Z' Values not being returned by vla-get-coordinates....

I have a 2 point LWPOLYLINE that has the following coordinates at its end point when I 'ID' the point.

Command: id
Specify point: end
of  X = 709369.3214     Y = 7153039.9690     Z = 269.2143

However if I use..

(vlax-safearray->list (vlax-variant-value (vla-get-coordinates (vlax-ename->vla-object (car (entsel))))))

I get this

(-450567.0 269.288 -450570.0 269.214)

and if I 'dump' the object..

;   Coordinates = (-450567.0 269.288 -450570.0 269.214)
;   Document (RO) = #<VLA-OBJECT IAcadDocument 09855674>
;   Elevation = 7.17399e+006

I don't have a clue where the '-450567.0' is coming from.

I'm in Model Space in 'World' UCS, and I'm confused..  why does the 'ID'd' value not reflect whats going on when I use the vla-get-coordinates approach.

There are many other LWPolylines within the same model that behave normally.

I've attached the drawing (I think!) If anyone can assist I would be very grateful.

 

7 REPLIES 7
Message 2 of 8
alanjt_
in reply to: petervose

Since the elevation for an LWPolyline is the same, it is not in the vla-get-coordinates dump. It can be retrieved with vla-get-elevation or just isloate all 10 and 38 codes from the dxf entget dump or use some of the vlax-curve* functions.

Message 3 of 8
petervose
in reply to: alanjt_

Thanks,  The coordinates returned using entget.. still hold strange values...The Z values are different at either end, not sure whether it has an elevation value though.    I now think it's somthing to do with extrusions.  The 'NORMAL' property (which I don't understand) has an odd value (0.0 0.998 0.347).  I need to work out what thatt's telling me, and whether theres a way to recreatete the polyline without this value.  Thanks for the post

Message 4 of 8
Lee_Mac
in reply to: petervose

LWPolyline Vertices are 2D and defined relative to the LWPolyline OCS (Object Coordinate System). This OCS is determined by its Normal Vector (DXF 210), and the Arbitrary Axis Algorithm. Similarly the Elevation of the LWPolyline (DXF 38) is also defined relative to the LWPolyline OCS.

 

Hence to retrieve a list of vertices in WCS, you will need to use the trans function to transform the coordinates from OCS to WCS, consider the following example:

 

(defun LWPolyVertices ( entity / elev elst )
    (setq elst (entget entity)
          elev (cdr (assoc 38 elst))
    )
    (apply 'append
        (mapcar
            (function
                (lambda ( pair )
                    (if (= 10 (car pair))
                        (list (trans (list (cadr pair) (caddr pair) elev) entity 0))
                    )
                )
            )
            elst
        )
    )
)

 

Supply the above with the Entity Name of the LWPolyline for which to return a list of 3D vertex coordinates in WCS.

Message 5 of 8
Kent1Cooper
in reply to: petervose


@petervose wrote:

Thanks,  The coordinates returned using entget.. still hold strange values...The Z values are different at either end.... ....  The 'NORMAL' property (which I don't understand) has an odd value (0.0 0.998 0.347).  I need to work out what thatt's telling me....


"Normal" is another word for "perpendicular", in this case the direction, in World Coordinate System terms, that is perpendicular to the drawing plane of the object.  If you draw a line in the WCS from 0,0,0 to (0.0 0.998 0.347), it will be parallel to the Z axis of that Polyline's Object Coordinate System [within the rounding tolerances of the displayed values, which in reality are stored to a much greater number of decimal places than three].

 

Things drawn in or parallel to the WCS X-Y plane always have Normal values of (0.0 0.0 1.0), straight up the WCS Z axis.

 

LWPolylines must be flat, and can't have different Z values from their own perspective [in their OCS].  That's why their vertices are not stored with Z coordinates [as, for example, 3DPolylines' vertices are], but instead, the overall object has an elevation, which is the OCS Z coordinate of all its vertices.  So the fact that a LWPolyline has different WCS Z values at the ends also means that it was not drawn in or parallel to the WCS X-Y plane, but is skewed from it.

 

EDIT:  A little more about Normals....  The value is the WCS location of the far corner of a rectangular prism, the corner opposite its "base" corner at WCS 0,0,0.  If you square the three values and add them, the total is always 1 -- it's a rectangular prism with a diagonal whose length is one drawing unit.  [It can be a rectangular prism with no thickness in one direction [just a rectangle] if one of the values is 0, and with no thickness in two directions [just a line] if two values are 0.]

 

On your Polyline, I get a Normal of (0.0361157 0.999348 0.0).  The 0.0 Z value means the normal lies in the WCS X-Y plane, and the relative sizes of the others mean that Normal aims way upward, that is, it's close to parallel to the Y axis [about 2 degrees clockwise from there].

Kent Cooper, AIA
Message 6 of 8
Kent1Cooper
in reply to: petervose


@petervose wrote:

I have a 2 point LWPOLYLINE that has the following coordinates at its end point when I 'ID' the point.

... X = 709369.3214     Y = 7153039.9690     Z = 269.2143

However if I use..

...(vla-get-coordinates...

I get this

(-450567.0 269.288 -450570.0 269.214)

.... 

I'm in Model Space in 'World' UCS, and I'm confused..  ....


The difference is that ID returns values in the current Coordinate System, but the VLA Coordinates Property, and the entity data list 10-code vertex values, are in the Object's Coordinate System.  For some object types, that's always the same as the WCS [so doing this for a Line, when in the WCS, you'd get the same values from ID and from the Coordinates Property], but not for LWPolylines.  This is from "Obtaining Entity Information" in the AutoLISP Reference:
 

All points associated with an object are expressed in terms of that object's object coordinate system (OCS). For point, line, 3D line, 3D face, 3D polyline, 3D mesh, and dimension objects, the OCS is equivalent to the WCS (the object points are World points). For all other objects, the OCS can be derived from the WCS and the object's extrusion direction (its 210 group). When working with objects that are drawn using coordinate systems other than the WCS, you may need to convert the points to the WCS or to the current UCS by using the trans function.

 

[The extrusion direction 210 group referred to is the same as the Normal Property.]

 

The Coordinates Property lists all vertices' coordinates mashed together into one undifferentiated list.  For a LWPolyline, since it only stores X & Y coordinates, the first two are those of the first vertex, and each successive pair represents another vertex.  For a 3DPolyline, the first three are those of the first vertex, including a Z value, and each successive set of three numbers is another vertex.

Kent Cooper, AIA
Message 7 of 8
petervose
in reply to: Kent1Cooper

As always I am bowled over by the comprehensive solutions I receive from this forum.  I've run the code provided and it does exactly what I've been struggling to do for a good part of my day!.  The explanation has also solved the mystery.  Thanks Very Much - really appreciated.

Pete

Message 8 of 8
Lee_Mac
in reply to: petervose

You're welcome Pete, glad to have lifted the confusion Smiley Happy

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost