Add block`s xyz rotation angles to it`s attributes

Add block`s xyz rotation angles to it`s attributes

Anonymous
Not applicable
1,186 Views
8 Replies
Message 1 of 9

Add block`s xyz rotation angles to it`s attributes

Anonymous
Not applicable

I want to use _DATAEXTRACTION to create a list containing all blocks, with their xyz position and rotation data, so i can recreate my models in UE4. Currently i can only export the blocks rotation and slope. Therefore it would be usefull to create a script I would run before the export that runs a batch process, adding every xyz rotation as an attribute or custom property to every block, so it can then be exported with _DATAEXTRACTION.

I am fairly new to scipting, could use some help on how to get stared with this. 

0 Likes
1,187 Views
8 Replies
Replies (8)
Message 2 of 9

pbejse
Mentor
Mentor

@Anonymous wrote:

I want to use _DATAEXTRACTION to create a list containing all blocks, with their xyz position....


 

What is UE4? what you're asking is not that difficult. just need to see the whole picture for us to undestrand

 

 

0 Likes
Message 3 of 9

leeminardi
Mentor
Mentor

I am not familiar with UE4 but a quick look at the x, y, z, w, format for rotation at 7:44 in this video indicates that it may be using quaternions for rotation.  Is that correct? AutoCAD stores 3D orientation and position in a 4 x 3 matrix.  Quats are used in animation to avoid gimbal lock which is not a problem in the static world of AutoCAD.

lee.minardi
0 Likes
Message 4 of 9

Sea-Haven
Mentor
Mentor

Pick a block you can see all the info that is easy to get at, look at dxf 2, 10 & 50, see what is displayed on screen. So making a loop to dump all blocks is easy. 

 

Just copy this to command line to see what is available,   (entget (car (entsel "\nPick a block")))

 

Can be in sorted order etc so once angle is defined post the details for the correct output order.

0 Likes
Message 5 of 9

Anonymous
Not applicable

@pbejse  By UE4 i meant Unreal engine 4

@leeminardi I`m looking for this input for every block item in my dwg. location and scale xyz are listed in the blocks properties, but xyz rotation is not. 

mathijsabrahams8354J_0-1615646611101.png

 

@Sea-Haven The command line function gives me some output, not sure what to do with it from there. Here is an example of the result it gives me : 

 

Pick a block((-1 . <Entity name: 4d1e9e10>) (0 . "INSERT") (5 . "51D6") (330 . <Entity name: 3daeb840>) (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "AXIS311-Ledgers") (370 . -1) (100 . "AcDbBlockReference") (2 . "Ledger_2072") (10 -3380.xxx-xxxxxxxx 1939.xxx-xxxxxxxx 223.999999999993) (41 . 1.0) (42 . 1.0) (43 . 1.0) (50 . 0.0) (70 . 0) (71 . 0) (44 . 0.0) (45 . 0.0) (210 0.0 0.0 1.0))

 

 

I`m new to writing code to use within my drawings, so all of your help is really appreciated. I`ve added an example of a dwg file i indend to use it on.

 

 

0 Likes
Message 6 of 9

leeminardi
Mentor
Mentor

The nentselp function will give you the homogeneous transformation matrix for a block.  The first column (the first element in the first three rows) are the x,y,z components of a unit vector point in the direction of the block's x axis.  The second element of each of the first three rows defines the y axis. Likewise, the third element is the z axis.

 

For example,

Command: (setq m (nentselp "\nSelect block"))
Select block(<Entity name: 18ecedf3660> (-1.8964 5.95947 0.0) ((-0.753685 0.644604 -0.128238 1.72511) (0.649655 0.701122 -0.293899 2.16951) (-0.0995379 -0.304817 -0.947195 3.63668) (0.0 0.0 0.0 1.0)) (<Entity name: 18ecedf36a0>))

The x axis unit vector for this block is:  -0.753685, 0.649655, -0.0995379 

The y and z vectors are similarly determined from the 2nd and third column.

 

If the block is scaled then these vectors would no longer have a magnitude of one but would be proportional to the scale in the direction of the vector.

 

The location of the block is the 4th column or: 1.72511, 2.16951, 3.63688

 

 

 

lee.minardi
0 Likes
Message 7 of 9

Anonymous
Not applicable

ok, i guess it is possible to calculate the x y and z rotations i need from those values, right?

 

then all i need is a script of some sort, that for every block in the dwg, calulates these values, and stores them as attributes to the block.

Then i can use _dataextraction to export these values, along with all other properties i need to export.

 

 

0 Likes
Message 8 of 9

leeminardi
Mentor
Mentor

The following will determine a block's location, the angles of rotation about the x,y, z axes, and the scale factors for the block in x, y, z.  Verify that the angles are what you need.

 

(defun c:test (/ m vx vy vz pos xrot xrotdeg yrot yrotdeg zrot zrotdeg xs ys zs)
; determines the position, rotation angles, and scale factors
;  of a block.
;  
  (setq m (nth 2 (nentselp "\nSelect block")))
  (setq vx (list (car (car m)) (car (cadr m)) (car (caddr m))))
  (setq vy (list (cadr (car m)) (cadr (cadr m)) (cadr (caddr m))))
  (setq vz (list (caddr (car m)) (caddr (cadr m)) (caddr (caddr m))))
  (setq
    pos	(list (cadddr (car m)) (cadddr (cadr m)) (cadddr (caddr m)))
  )
  (princ "\nBlock position: ")
  (princ pos)
  (setq xrot (angle '(0.0 0.0 0.0) (list (cadr vx) (caddr vx) 0.0)))
  (setq xrotdeg (* xrot (/ 180. pi)))
  (setq yrot (angle '(0.0 0.0 0.0) (list (car vx) (caddr vx))))
  (setq yrotdeg (* yrot (/ 180. pi)))
  (setq zrot (angle '(0.0 0.0 0.0) (list (car vx) (cadr vx) 0.0)))
  (setq zrotdeg (* zrot (/ 180. pi)))
  (princ "\nBlock rotation (degrees) about the x, y, z axes are: ")
  (princ (list xrotdeg yrotdeg zrotdeg))
  (setq	xs (/ (distance '(0.0 0.0 0.0) vx) 1.0)
	ys (/ (distance '(0.0 0.0 0.0) vy) 1.0)
	zs (/ (distance '(0.0 0.0 0.0) vz) 1.0)
  )
  (princ "\nBlock scale factors in x, y, z are: ")
  (princ (list xs ys zs))
  (princ)
)

 

lee.minardi
0 Likes
Message 9 of 9

Anonymous
Not applicable

Yes, these are the angles i need, works great.

0 Likes