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
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.
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 🙂
...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)
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 🙂
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!
@Anonymous 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."
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.
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. 🙂
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!
For simple 2D objects like circles and text, the information is stored in the 210 code for the rotation of the z axis. For solids, the entire geiometry seems to be encoded with a series of 1 codes. The Help says it proprietary, so AutoDesk might not want you to know about that.
@Anonymous wrote:For simple 2D objects like circles and text, the information is stored in the 210 code for the rotation of the z axis. ....
This thread may be dead after more than a year [davetyner, are you still out there?], but just in case....
I'm not at all sure that the extrusion direction is what they're looking for. Message 5 [if you have them chronologically] suggests to me that maybe they're looking for a rotation for Text/Mtext as an XYZ vector rather than as an angle in radians in the drawing plane of the object. So, for instance, for a piece of Text that's in the WCS plane, with a rotation angle of 0, the (assoc 210) extrusion direction would be 0,0,1, but I think the rotational vector they're looking for would be [if they want a unit vector] 1,0,0. After all, whatever the (assoc 50) rotation is for Text in the WCS, the (assoc 210) extrusion direction would be the same, whereas the rotational vector [if what they mean for ordinary left-justified Text is the direction from the insertion point along the baseline] would vary with the rotation -- 1,0,0 for 0 degrees, 0,1,0 for 90 degrees, etc.
I'm hoping for some elaboration from the OP about whether that's what they're after, and particularly in answer to the question at the beginning of my first reply.
Kent, I mispoke if it sounded as if the 210 code was a direct rotational value, as in degrees or radians. It's a vector based on diistances in each X,Y,Z direction from 0,0,0 that would result in a line with a length of 1 at the rotational angle. It's been a few years since I was doing 3D modeling on a regular basis, but a subject I was interested in knowing a little more about. As much as possible I use entmake and other DXF code manipulation to crete/modify object in AutoCAD. Knowing how to do it for 3D work would be handy to know. I see no easy answers for working with solids, but simple 2D objects are simple enough to work with that way.Besides, I'm waiting for a new project to start and I was bored.
It give nil for a 3DSOLID
Exactly. They are doing something completely different for 3D solids. The 210 code is for text, circles and other simple objects. A 3D solid has not 210 code at all. Instead, is has numberous 1 codes with proprietary data.