Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Contributor
davetyner
Posts: 22
Registered: ‎08-19-2010
Message 1 of 15 (1,229 Views)

LISP to find Position XYZ and Rotation XYZ of each entity?

1229 Views, 14 Replies
07-13-2011 05:23 PM

Hello, I am looking for some help finding each objects Position XYZ and Rotation XYZ using LISP.  It looks like position is a pretty easy one but rotation data is a bit elusive.  

 

Thanks in advance,

 

Dave

Valued Mentor
Shneuph
Posts: 353
Registered: ‎11-26-2007
Message 2 of 15 (1,227 Views)

Re: LISP to find Position XYZ and Rotation XYZ of each entity?

07-13-2011 05:38 PM in reply to: davetyner

These are the objects you can easily get the rotation ange from using visuallisp.  If you want the rotation of other objects it will be slightly more difficult.  What objects do you want to get the rotation of?

 

Something like:

(setq object (vlax-ename->vla-object (car (entsel "\nSelect Object to list it's Rotation:  "))))

(cvunit (vla-get-rotation object) "radian" "degree")

 

 

From AutoCAD Help Files:

 

Attribute, AttributeReference, BlockRef, Dim3PointAngular, DimAligned, DimAngular, DimArcLength, DimDiametric, DimOrdinate, DimRadial, DimRadialLarge, DimRotated, DwfUnderlay, ExternalReference, MInsertBlock, MText, Raster, Shape, Text, Underlay, Wipeout

 

The objects this property applies to.

Rotation

Double; read-write
The rotation angle in radians.



---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
Contributor
davetyner
Posts: 22
Registered: ‎08-19-2010
Message 3 of 15 (1,225 Views)

Re: LISP to find Position XYZ and Rotation XYZ of each entity?

07-13-2011 05:41 PM in reply to: Shneuph

Thank you for your reply!

 

I actually need the xyz position and xyz rotation data of EVERY object in my file.  I will test your code and report back :smileyhappy:

Valued Mentor
Shneuph
Posts: 353
Registered: ‎11-26-2007
Message 4 of 15 (1,224 Views)

Re: LISP to find Position XYZ and Rotation XYZ of each entity?

07-13-2011 05:42 PM in reply to: davetyner

...I'm sorry.  The OP said "using autolisp".  I don't know if you want to use VisualLISP functions or not but for instance the DXF group code 50 of an Mtext object is the rotation angle in Radians...

 

(setq MTObject (entget (car (entsel "Select Mtext: "))))

(princ (strcat "Rotation Angle is: " (rtos (cvunit (cdr (assoc 50 MTObject)) "radian" "degree"))))(princ)

---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
Contributor
davetyner
Posts: 22
Registered: ‎08-19-2010
Message 5 of 15 (1,221 Views)

Re: LISP to find Position XYZ and Rotation XYZ of each entity?

07-13-2011 05:52 PM in reply to: Shneuph

Your code for the mText does indeed give me a rotation but only for a single vector.  I need all three x y and z rotations :smileyhappy:

Contributor
davetyner
Posts: 22
Registered: ‎08-19-2010
Message 6 of 15 (1,212 Views)

Re: LISP to find Position XYZ and Rotation XYZ of each entity?

07-13-2011 10:35 PM in reply to: davetyner



Here is what I have. It's a 3D object (cylinder with a bend). I really don't know too much about autolisp but, surely there must be a way to extract the position xyz and rotation xyz of this object?

Thanks!

*Expert Elite*
Kent1Cooper
Posts: 5,795
Registered: ‎09-13-2004
Message 7 of 15 (1,200 Views)

Re: LISP to find Position XYZ and Rotation XYZ of each entity?

07-14-2011 05:40 AM in reply to: davetyner

davetyner wrote:

....

Here is what I have. It's a 3D object (cylinder with a bend). ...there must be a way to extract the position xyz and rotation xyz of this object?
...


And what is the "rotation XYZ" of that object, that you would want extracted?  The straight direction from the center of one end to the center of the other?  The tangent direction that it's heading away from the origin [perpendicular to one end face if it's sliced perpendicularly]?  Something else?

 

For some things, the extrusion direction:

(cdr (assoc 210 entitydata))

might be what you want.  For Lines, I imagine simply subtracting the end point from the start point:

(mapcar '- (cdr (assoc 10 entitydata)) (cdr (assoc 11 entitydata)))

might be what you want.  But for some things, it's hard to imagine what you would want -- a 3DPolyline, for instance, or any irregularly shaped 3D Solid, or any regularly shaped one without some clear "direction," such as a sphere.

 

Even if you can define what would be considered the "rotation" for a 3D Solid, the information AutoCAD stores about such things is so mysterious that it's hard to imagine how you would calculate anything from it.  For instance, if you wanted the direction from the center of one end face of your curved cylinder to the center of the other face, I'm not even sure it's possible to get those locations from anything like the entity data, and that could mean you can't extract the "position" any more easily than the "rotation."

Kent Cooper
*Expert Elite*
dgorsman
Posts: 5,611
Registered: ‎10-12-2006
Message 8 of 15 (1,186 Views)

Re: LISP to find Position XYZ and Rotation XYZ of each entity?

07-14-2011 09:47 AM in reply to: Kent1Cooper

Yup.  Once you get into 3D solids its time to break out the matrix algebra and other complex math.  There *might* be a way to handle relative rotations and positions, using XDATA attached to each object on creation.  Some of the XDATA values return relative values from the objects original position and orientation.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
Adopt. Adapt. Overcome. Or be overcome.
A good question will be halfway to a good answer.


Contributor
davetyner
Posts: 22
Registered: ‎08-19-2010
Message 9 of 15 (1,183 Views)

Re: LISP to find Position XYZ and Rotation XYZ of each entity?

07-14-2011 09:55 AM in reply to: dgorsman

Right, and digging into the vector, matrix, and object transform math with it's 16 rows/columns and normalized vector data is what prompted this question. :smileyhappy:

 

I just find it hard to beleive there is not some simpler way to extract an objects relative pos/rot xyz.  I was pretty decent at math, 20 years ago! Looks like it's time to hit the books!

Mentor
devitg
Posts: 1,705
Registered: ‎03-14-2004
Message 10 of 15 (884 Views)

Re: LISP to find Position XYZ and Rotation XYZ of each entity?

10-05-2012 11:27 AM in reply to: davetyner

Please UPLOAD your dwg

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!