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,
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?
(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.
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?
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!
Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.