Author Topic: 3Dalign an object, and know by how much it was rotated (x,y,z rotations)  (Read 2811 times)

0 Members and 1 Guest are viewing this topic.

lbernardi

  • Guest
Hi all, first post here! I've been at AutoLISP for a month with this internship and have been waiting for my first problem to arise to ask a question here. My problem is this. We have a drill hole that gets 3daligned to a new angle, I need to know what the new angle is after. All i need to know is how much the current way of doing it (3dalign) changes it by. The problem is 3dalign being an autocad not autolisp command isn't going to give me any info. Is there any other autocad commands which can tell me how much the last change was? or an autolisp/visuallisp way of 3daligning which will give me that info? Thanks and good weekend! and thanks for all your other posts and answers, this site is an AMAZING reference.

Lou

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: 3Dalign an object, and know by how much it was rotated (x,y,z rotations)
« Reply #1 on: October 03, 2014, 07:05:04 PM »
Welcome to the Swamp!  8-)

What type of object is your 'drill hole' (i.e. block reference / circle / 3D solid etc). If the object is planar, you could store the defining geometry (i.e. extrusion vector, position, rotation, etc.) and see how these properties are altered following the transformation. If the object is 3D, you may be able to interpret the changes to properties such as the Principal Directions / Centroid etc.

Alternatively, you could use a wrapper for the 3DALIGN command so that you can intercept & analyse the user input before passing it to the 3DALIGN command.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: 3Dalign an object, and know by how much it was rotated (x,y,z rotations)
« Reply #2 on: October 03, 2014, 11:33:53 PM »
Welcome to the Swamp Lou.
You are in good hands. 8)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: 3Dalign an object, and know by how much it was rotated (x,y,z rotations)
« Reply #3 on: October 04, 2014, 06:20:33 AM »
Following Lee Mac's wisdom to intercept & analyze the user input before passing it to the ALIGN command, I wrote this function... Only now I see that you're searching for 3DALIGN... Never mind, I wrote it for ALIGN in 3D...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:XYZangalign ( / ss p1 p2 p3 p4 p5 p6 l v xa ya za )
  2.   (prompt "\nSelect object(s) to perform 3D Align with retriving XYZ axises rotation angles...")
  3.   (while (not ss) (setq ss (ssget "_:L")))
  4.   (while (not p1) (setq p1 (getpoint "\nPick or specify first source point : ")))
  5.   (while (not p2) (setq p2 (getpoint p1 "\nPick or specify first destination point : ")))
  6.   (while (not p3) (setq p3 (getpoint "\nPick or specify second source point : ")))
  7.   (while (not p4) (setq p4 (getpoint p3 "\nPick or specify second destination point : ")))
  8.   (setq p5 (getpoint "\nPick or specify third source point <continue> : "))
  9.   (if (not (null p5))
  10.     (while (not p6) (setq p6 (getpoint p5 "\nPick or specify third destination point : ")))
  11.   )
  12.   (setq l (entmakex '((0 . "LINE") (10 0.0 0.0 0.0) (11 0.0 0.0 1.0))))
  13.   (ssadd l ss)
  14.   (if (and p5 p6)
  15.     (command "_.ALIGN" ss "" "_none" p1 "_none" p2 "_none" p3 "_none" p4 "_none" p5 "_none" p6)
  16.     (command "_.ALIGN" ss "" "_none" p1 "_none" p2 "_none" p3 "_none" p4)
  17.   )
  18.   (while (> (getvar 'cmdactive) 0) (command ""))
  19.   (setq v (mapcar '- (cdr (assoc 11 (entget l))) (cdr (assoc 10 (entget l)))))
  20.   (setq xa (angle '(0.0 0.0) (list (cadr v) (caddr v))))
  21.   (setq ya (angle '(0.0 0.0) (list (car v) (caddr v))))
  22.   (setq za (angle '(0.0 0.0) (list (car v) (cadr v))))
  23.   (prompt "\nRotation angle around X axis : ") (princ (rtos (cvunit xa "radians" "degrees") 2 50)) (prompt " degrees")
  24.   (prompt "\nRotation angle around Y axis : ") (princ (rtos (cvunit ya "radians" "degrees") 2 50)) (prompt " degrees")
  25.   (prompt "\nRotation angle around Z axis : ") (princ (rtos (cvunit za "radians" "degrees") 2 50)) (prompt " degrees")
  26.   (entdel l)
  27.   (princ)
  28. )
  29.  

HTH
« Last Edit: October 04, 2014, 06:29:11 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

lbernardi

  • Guest
Re: 3Dalign an object, and know by how much it was rotated (x,y,z rotations)
« Reply #4 on: October 06, 2014, 10:06:54 AM »
Following Lee Mac's wisdom to intercept & analyze the user input before passing it to the ALIGN command, I wrote this function... Only now I see that you're searching for 3DALIGN... Never mind, I wrote it for ALIGN in 3D...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:XYZangalign ( / ss p1 p2 p3 p4 p5 p6 l v xa ya za )
  2.   (prompt "\nSelect object(s) to perform 3D Align with retriving XYZ axises rotation angles...")
  3.   (while (not ss) (setq ss (ssget "_:L")))
  4.   (while (not p1) (setq p1 (getpoint "\nPick or specify first source point : ")))
  5.   (while (not p2) (setq p2 (getpoint p1 "\nPick or specify first destination point : ")))
  6.   (while (not p3) (setq p3 (getpoint "\nPick or specify second source point : ")))
  7.   (while (not p4) (setq p4 (getpoint p3 "\nPick or specify second destination point : ")))
  8.   (setq p5 (getpoint "\nPick or specify third source point <continue> : "))
  9.   (if (not (null p5))
  10.     (while (not p6) (setq p6 (getpoint p5 "\nPick or specify third destination point : ")))
  11.   )
  12.   (setq l (entmakex '((0 . "LINE") (10 0.0 0.0 0.0) (11 0.0 0.0 1.0))))
  13.   (ssadd l ss)
  14.   (if (and p5 p6)
  15.     (command "_.ALIGN" ss "" "_none" p1 "_none" p2 "_none" p3 "_none" p4 "_none" p5 "_none" p6)
  16.     (command "_.ALIGN" ss "" "_none" p1 "_none" p2 "_none" p3 "_none" p4)
  17.   )
  18.   (while (> (getvar 'cmdactive) 0) (command ""))
  19.   (setq v (mapcar '- (cdr (assoc 11 (entget l))) (cdr (assoc 10 (entget l)))))
  20.   (setq xa (angle '(0.0 0.0) (list (cadr v) (caddr v))))
  21.   (setq ya (angle '(0.0 0.0) (list (car v) (caddr v))))
  22.   (setq za (angle '(0.0 0.0) (list (car v) (cadr v))))
  23.   (prompt "\nRotation angle around X axis : ") (princ (rtos (cvunit xa "radians" "degrees") 2 50)) (prompt " degrees")
  24.   (prompt "\nRotation angle around Y axis : ") (princ (rtos (cvunit ya "radians" "degrees") 2 50)) (prompt " degrees")
  25.   (prompt "\nRotation angle around Z axis : ") (princ (rtos (cvunit za "radians" "degrees") 2 50)) (prompt " degrees")
  26.   (entdel l)
  27.   (princ)
  28. )
  29.  

HTH

Thanks Ribarm, you gave me some ideas on how to do it. Thanks for the effort!

lbernardi

  • Guest
Re: 3Dalign an object, and know by how much it was rotated (x,y,z rotations)
« Reply #5 on: October 06, 2014, 10:08:25 AM »
Welcome to the Swamp!  8-)

What type of object is your 'drill hole' (i.e. block reference / circle / 3D solid etc). If the object is planar, you could store the defining geometry (i.e. extrusion vector, position, rotation, etc.) and see how these properties are altered following the transformation. If the object is 3D, you may be able to interpret the changes to properties such as the Principal Directions / Centroid etc.

Alternatively, you could use a wrapper for the 3DALIGN command so that you can intercept & analyse the user input before passing it to the 3DALIGN command.

I felt kind of silly after figuring out how to do it but obviously storing the geometry before and after and comparing worked. I was worried it wouldn't (why I posted) because we use a lot of mining specific measurements in our code.