Author Topic: Marko, How Rotating 3D SOLID quickly ?  (Read 9550 times)

0 Members and 1 Guest are viewing this topic.

andy_lee

  • Newt
  • Posts: 147
Marko, How Rotating 3D SOLID quickly ?
« on: May 26, 2015, 02:26:00 AM »
Hi marko .

Sometimes , need import 3D solid from  solidworks. (solidworks export "*.STEP" format , autocad import )

But , when import it……

This is "Front" view ,is not I need.


This is I need.


This is "SW ISOMETRIC" view ,is not I need.


This is I need



So, when I import it  ,How quick rotate  3D SOLID  to what I need  ?

1. choose all 3D object ,2. Choose a face  align X axis , 3. Choose a face align Y axis ?

Test DWG at #2



======================================================================













=======================================================================

« Last Edit: May 26, 2015, 02:54:34 AM by emk2012 »
andy.
Best regards.

andy_lee

  • Newt
  • Posts: 147
Re: Marko, How Rotating 3D SOLID quickly ?
« Reply #1 on: May 26, 2015, 03:00:21 AM »
command "_3drotate" is not I need.

Specify base point:
Pick a rotation axis: difficile to pick
Specify angle start point or type an angle:  I don't know the angle

This is Test.dwg
andy.
Best regards.

ribarm

  • Gator
  • Posts: 3255
  • Marko Ribar, architect
Re: Marko, How Rotating 3D SOLID quickly ?
« Reply #2 on: May 26, 2015, 06:07:38 AM »
Emk, I don't have my comp. at the moment and I am typing this from my phone... I am away from where I live and cant answer you until I came back home... Hope youll find solution and without my help... Sorry, but I cant analyze your request the way I would like to... Have a nice day and my regards to you and all swampers... M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

andy_lee

  • Newt
  • Posts: 147
Re: Marko, How Rotating 3D SOLID quickly ?
« Reply #3 on: May 26, 2015, 06:26:12 AM »
Emk, I don't have my comp. at the moment and I am typing this from my phone... I am away from where I live and cant answer you until I came back home... Hope youll find solution and without my help... Sorry, but I cant analyze your request the way I would like to... Have a nice day and my regards to you and all swampers... M.R.

Hi Marko. I can't find any solution from THESWAMP and CADTUTOR , but I can wait for you.
Thank you very much .

Best regards!
andy.
Best regards.

ribarm

  • Gator
  • Posts: 3255
  • Marko Ribar, architect
Re: Marko, How Rotating 3D SOLID quickly ?
« Reply #4 on: May 26, 2015, 07:46:49 AM »
Emk, Ill be absent for ab 2 weeks... I am sure someone will reply till then... My kind regards, Marko...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Marko, How Rotating 3D SOLID quickly ?
« Reply #5 on: May 26, 2015, 10:01:26 AM »
Here is a solution using the TransformBy method.
The function c:test uses InverseMatrix by Gile.
The final result will vary depending on the selected face but also on the point that was picked in the selection process.
Code - Auto/Visual Lisp: [Select]
  1. ;; http://www.theswamp.org/index.php?topic=22638.msg334208#msg334208
  2. ;; InverseMatrix (gile) 2009/03/17
  3. ;; Uses the Gauss-Jordan elimination method to calculate the inverse
  4. ;; matrix of any dimension square matrix
  5. ;;
  6. ;; Argument : a square matrix
  7. ;; Return : the inverse matrix (or nil if singular)
  8. (defun InverseMatrix (mat / col piv row res)
  9.   (setq mat (mapcar '(lambda (x1 x2) (append x1 x2)) mat (Imat (length mat))))
  10.   (while mat
  11.     (setq col (mapcar '(lambda (x) (abs (car x))) mat))
  12.     (repeat (vl-position (apply 'max col) col)
  13.       (setq mat (append (cdr mat) (list (car mat))))
  14.     )
  15.     (if (equal (setq piv (caar mat)) 0.0 1e-14)
  16.       (setq mat nil
  17.             res nil
  18.       )
  19.       (setq piv (/ 1.0 piv)
  20.             row (mapcar '(lambda (x) (* x piv)) (car mat))
  21.             mat (mapcar
  22.                   '(lambda (r / e)
  23.                      (setq e (car r))
  24.                      (cdr (mapcar '(lambda (x n) (- x (* n e))) r row))
  25.                   )
  26.                   (cdr mat)
  27.                 )
  28.             res (cons
  29.                   (cdr row)
  30.                   (mapcar
  31.                     '(lambda (r / e)
  32.                        (setq e (car r))
  33.                        (cdr (mapcar '(lambda (x n) (- x (* n e))) r row))
  34.                      )
  35.                     res
  36.                   )
  37.                 )
  38.       )
  39.     )
  40.   )
  41.   (reverse res)
  42. )
  43.  
  44. ;; http://www.theswamp.org/index.php?topic=22638.msg334208#msg334208
  45. ;; IMAT (gile)
  46. ;; Returns the specified dimension identity matrix
  47. ;;
  48. ;; Argument
  49. ;; d : the matrix dimension (positive integer)
  50. (defun Imat (d / i n r m)
  51.   (setq i d)
  52.   (while (<= 0 (setq i (1- i)))
  53.     (setq n d r nil)
  54.     (while (<= 0 (setq n (1- n)))
  55.       (setq r (cons (if (= i n) 1.0 0.0) r))
  56.     )
  57.     (setq m (cons r m))
  58.   )
  59. )
  60.  
  61. (defun _Conv_Pickset_To_EnameList (ss / i ret)
  62.   (if ss
  63.     (repeat (setq i (sslength ss))
  64.       (setq ret (cons (ssname ss (setq i (1- i))) ret))
  65.     )
  66.   )
  67. )
  68.  
  69. (defun c:test ( / doc mat name ss)
  70.   (if (= (logand (getvar 'undoctl) 8) 8)
  71.     (vla-endundomark doc)
  72.   )
  73.   (if (setq ss (ssget))
  74.     (progn
  75.       (setvar 'cmdecho 0)
  76.       (setq name (strcat "TMP_UCS_" (rtos (getvar 'cdate) 2 8)))
  77.       (princ "\nSelect face for top: ")
  78.       (command "_.ucs" "_face" "\\" "")
  79.       (command "_.ucs" "_named" "_save" name)
  80.       (setq mat
  81.         (vlax-tmatrix
  82.           (InverseMatrix (vlax-invoke (vla-get-activeucs doc) 'getucsmatrix))
  83.         )
  84.       )
  85.       (foreach ent (_Conv_Pickset_To_EnameList ss)
  86.         (vla-transformby (vlax-ename->vla-object ent) mat)
  87.       )
  88.       (command "_.ucs" "_world")
  89.       (command "_.ucs" "_named" "_delete" name)
  90.       (setvar 'cmdecho 1)
  91.     )
  92.   )
  93.   (princ)
  94. )
« Last Edit: May 26, 2015, 10:08:32 AM by roy_043 »

HofCAD

  • Guest
Re: Marko, How Rotating 3D SOLID quickly ?
« Reply #6 on: May 26, 2015, 10:05:59 AM »
Dear Emk,

Select the command Align
 1) Select all objects
 2) Specify first source point: S1
 3) Specify first destination point: 0.0
 4) Specify second source point: S2
 5) Specify second destination point: 0,0,1
 6) Specify third source point S3
 7) Specify third destination point: 0.1

Regards

andy_lee

  • Newt
  • Posts: 147
Re: Marko, How Rotating 3D SOLID quickly ?
« Reply #7 on: May 26, 2015, 08:21:12 PM »
Here is a solution using the TransformBy method.
The function c:test uses InverseMatrix by Gile.
The final result will vary depending on the selected face but also on the point that was picked in the selection process.

Many thanks roy. but
Select objects:
Select face for top: ; error: multi dimension safearray not supported
andy.
Best regards.

andy_lee

  • Newt
  • Posts: 147
Re: Marko, How Rotating 3D SOLID quickly ?
« Reply #8 on: May 26, 2015, 08:29:46 PM »
Dear Emk,

Select the command Align
 1) Select all objects
 2) Specify first source point: S1
 3) Specify first destination point: 0.0
 4) Specify second source point: S2
 5) Specify second destination point: 0,0,1
 6) Specify third source point S3
 7) Specify third destination point: 0.1

Regards

Dear Hof
I test ,but unsuccessful , and this method is not simple.

I think ,if need specify three point, can use coding ?  eg. choose a face ,can get 4 point .
andy.
Best regards.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Marko, How Rotating 3D SOLID quickly ?
« Reply #9 on: May 27, 2015, 03:06:56 AM »
My code works fine on BricsCAD.
Maybe it will work on AutoCAD if you change:
Code - Auto/Visual Lisp: [Select]
  1.       (setq mat
  2.         (vlax-tmatrix
  3.           (InverseMatrix (vlax-invoke (vla-get-activeucs doc) 'getucsmatrix))
  4.         )
  5.       )
To:
Code - Auto/Visual Lisp: [Select]
  1.       (setq mat
  2.         (vlax-tmatrix
  3.           (InverseMatrix
  4.             (vlax-safearray->list
  5.               (vlax-variant-value (vla-getucsmatrix (vla-get-activeucs doc)))
  6.             )
  7.           )
  8.         )
  9.       )

HofCAD

  • Guest
Re: Marko, How Rotating 3D SOLID quickly ?
« Reply #10 on: May 27, 2015, 03:18:27 AM »
Dear Emk,

Set all Dynamic Input features, including dynamic prompts, off (DYNMODE 0).
Otherwise you must provide the destination points 0,0 , 0,0,1 and 0,1
with an asterisk *0,0 , *0,0,1 and *0,1.
Turn the running object snap settings for Endpoint on,
or type the abbreviation END!
Then you can snap the Endpoints S1,S2 and S3!

Command: ALIGN
Select objects: ALL
4 found
Select objects: ‘Enter’
Specify first source point: END of ‘pick S1’
Specify first destination point: 0,0
Specify second source point: END of ‘pick S2’
Specify second destination point: 0,0,1
Specify third source point or <continue>: END of ‘pick S3’
Specify third destination point: 0,1

Explanation:
The selected objects move from the source point S1 to the destination point 0,0.
The selected object is rotated (S1 and S2) so that it aligns with the destination object (0,0 and 0,0,1).
The selected object is then rotated again (S2 and S3) so that it aligns with the destination object (0,0,1 and 0,1).

http://knowledge.autodesk.com/support/autocad/learn-explore/caas/CloudHelp/cloudhelp/2015/ENU/AutoCAD-Core/files/GUID-D0FA10D5-76EE-4B80-A285-43C7F39916DB-htm.html

Regards
« Last Edit: May 27, 2015, 07:24:22 AM by HofCAD »

andy_lee

  • Newt
  • Posts: 147
Re: Marko, How Rotating 3D SOLID quickly ?
« Reply #11 on: May 27, 2015, 03:30:58 AM »
My code works fine on BricsCAD.
Maybe it will work on AutoCAD if you change:
Code - Auto/Visual Lisp: [Select]
  1.       (setq mat
  2.         (vlax-tmatrix
  3.           (InverseMatrix (vlax-invoke (vla-get-activeucs doc) 'getucsmatrix))
  4.         )
  5.       )
To:
Code - Auto/Visual Lisp: [Select]
  1.       (setq mat
  2.         (vlax-tmatrix
  3.           (InverseMatrix
  4.             (vlax-safearray->list
  5.               (vlax-variant-value (vla-getucsmatrix (vla-get-activeucs doc)))
  6.             )
  7.           )
  8.         )
  9.       )


Many thanks ,roy .
It's so Beautiful!  This is " Select face for top " , how change to " select face for front " ?
andy.
Best regards.

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Marko, How Rotating 3D SOLID quickly ?
« Reply #12 on: May 27, 2015, 03:47:59 AM »
Many thanks ,roy .
It's so Beautiful!  This is " Select face for top " , how change to " select face for front " ?

Try changing:
Code - Auto/Visual Lisp: [Select]
  1.       (princ "\nSelect face for top: ")
  2.       (command "_.ucs" "_face" "\\" "")
  3.       (command "_.ucs" "_named" "_save" name)

to:
Code - Auto/Visual Lisp: [Select]
  1.       (princ "\nSelect face for front: ")
  2.       (command "_.ucs" "_face" "\\" "" "_.ucs" "_x" "-90" "_.ucs" "_named" "_save" name)

andy_lee

  • Newt
  • Posts: 147
Re: Marko, How Rotating 3D SOLID quickly ?
« Reply #13 on: May 27, 2015, 03:57:39 AM »
Dear Emk,

Turn the running object snap settings for Endpoint on,
or type the abbreviation END!
Then you can snap the Endpoints S1,S2 and S3!

Command: ALIGN
Select objects: ALL
4 found
Select objects: ‘Enter’
Specify first source point: END of ‘pick S1’
Specify first destination point: 0,0,0
Specify second source point: END of ‘pick S2’
Specify second destination point: 0,0,1
Specify third source point or <continue>: END of ‘pick S3’
Specify third destination point: 0,1

Explanation:
The selected objects move from the source point S1 to the destination point 0,0,0.
The selected object is rotated (S1 and S2) so that it aligns with the destination object (0,0,0 and 0,0,1).
The selected object is then rotated again (S2 and S3) so that it aligns with the destination object (0,0,1 and 0,1).

http://knowledge.autodesk.com/support/autocad/learn-explore/caas/CloudHelp/cloudhelp/2015/ENU/AutoCAD-Core/files/GUID-D0FA10D5-76EE-4B80-A285-43C7F39916DB-htm.html

Regards

Dear Hof
Many thanks ,  successful!!! 
before,unsuccessful , Because.  "Dynamic Input " is Enable.  so if I enter "0,0,0" will become to "@0,0,0"






andy.
Best regards.

andy_lee

  • Newt
  • Posts: 147
Re: Marko, How Rotating 3D SOLID quickly ?
« Reply #14 on: May 27, 2015, 04:08:07 AM »
Many thanks ,roy .
It's so Beautiful!  This is " Select face for top " , how change to " select face for front " ?

Try changing:
Code - Auto/Visual Lisp: [Select]
  1.       (princ "\nSelect face for top: ")
  2.       (command "_.ucs" "_face" "\\" "")
  3.       (command "_.ucs" "_named" "_save" name)

to:
Code - Auto/Visual Lisp: [Select]
  1.       (princ "\nSelect face for front: ")
  2.       (command "_.ucs" "_face" "\\" "" "_.ucs" "_x" "-90" "_.ucs" "_named" "_save" name)


Many thanks , Lee,  It's very nice !
andy.
Best regards.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Marko, How Rotating 3D SOLID quickly ?
« Reply #15 on: May 27, 2015, 04:10:33 AM »
Thanks for jumping in Lee.
BTW: Strange limitation for (vlax-invoke) on AutoCAD.

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Marko, How Rotating 3D SOLID quickly ?
« Reply #16 on: May 27, 2015, 04:39:14 AM »
Many thanks , Lee,  It's very nice !

You're welcome - all credit to roy  :-)

Thanks for jumping in Lee.
BTW: Strange limitation for (vlax-invoke) on AutoCAD.

No worries roy - I agree, it is strange that vlax-invoke was only implemented for 1-dimensional arrays in AutoCAD.

andy_lee

  • Newt
  • Posts: 147
Re: Marko, How Rotating 3D SOLID quickly ?
« Reply #17 on: May 27, 2015, 04:58:09 AM »
roy , lee , Hof ,marko
Your help was greatly appreciated.
« Last Edit: May 27, 2015, 08:58:06 AM by emk2012 »
andy.
Best regards.

andy_lee

  • Newt
  • Posts: 147
Re: Marko, How Rotating 3D SOLID quickly ?
« Reply #18 on: October 14, 2016, 06:50:45 AM »
Thanks for jumping in Lee.
BTW: Strange limitation for (vlax-invoke) on AutoCAD.

@roy_043
@Lee Mac
@ribarm

Dear Sir.
I am so sorry .I need to trouble you again.
Sometimes I use Roy's code Still have  a small problem.

Before,  I said:
I Need FRONT view like this:


But some times like this :

Or like this:

SO, There are four possibilities.

I think that must choose Two face ,  like this :
>>>Select face for front:
>>>Select face for top:

like this, the result is unique.

How modify this code ?  Thanks again!
andy.
Best regards.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Marko, How Rotating 3D SOLID quickly ?
« Reply #19 on: October 17, 2016, 05:20:26 AM »
Andy, you should experiment with the point you use to select the face.
The final result will vary depending on the selected face but also on the point that was picked in the selection process.

andy_lee

  • Newt
  • Posts: 147
Re: Marko, How Rotating 3D SOLID quickly ?
« Reply #20 on: October 17, 2016, 10:35:35 AM »
Andy, you should experiment with the point you use to select the face.
The final result will vary depending on the selected face but also on the point that was picked in the selection process.

Andy, you should experiment with the point you use to select the face.
The final result will vary depending on the selected face but also on the point that was picked in the selection process.

Hi Roy. Thank you for your reply.

I use @HofCAD 's method.

Code: [Select]
(if
(setq ent (xd::ssget "\n>>>Choose 3D SOLID <Exit>:" '(":L" ((0 . "3DSOLID")))))
(progn
(while (not(setq ss1 (osnap (getpoint "\n>>>1.Pick a basic point: ") "endp" ))))
(while (not(setq ss2 (osnap (getpoint "\n>>>2.Pick a point on X axis: ") "endp" ))))
(while (not(setq ss3 (osnap (getpoint "\n>>>3.Pick a point on Z axis: ") "endp" ))))
(command "_.align" ent ""
"_non" ss1 "_non" "0,0"
"_non" ss2 "_non" "1,0,0"
"_non" ss3 "_non" "0,0,1"
)
(command "_.view" "_front" )
);end_progn
);end_if
andy.
Best regards.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Marko, How Rotating 3D SOLID quickly ?
« Reply #21 on: October 17, 2016, 11:40:08 AM »
Sometimes I use Roy's code Still have  a small problem.
I use @HofCAD 's method.
?

But if you use the _Align command why not align along the X and Y-axis, instead of the X and Z-axis?

andy_lee

  • Newt
  • Posts: 147
Re: Marko, How Rotating 3D SOLID quickly ?
« Reply #22 on: October 18, 2016, 04:31:50 AM »
Sometimes I use Roy's code Still have  a small problem.
I use @HofCAD 's method.
?

But if you use the _Align command why not align along the X and Y-axis, instead of the X and Z-axis?


Hi Roy ,  align along the X and Y-axis & align along the X and Z-axis  is the same ,  all ok.

I think use " align along the X and Z-axis " is  easily . Because this two point on the same face. :smitten:

andy.
Best regards.

ahsattarian

  • Newt
  • Posts: 112
Re: Marko, How Rotating 3D SOLID quickly ?
« Reply #23 on: November 04, 2022, 03:15:37 PM »
Try This  :   




Code - Auto/Visual Lisp: [Select]
  1. (defun c:al3 ()
  2.   (defun sub1 (v1 v2) ;|  Cross product of two vectors - #Normal Vector  |;
  3.     (list
  4.       (- (* (cadr v1) (caddr v2)) (* (caddr v1) (cadr v2)))
  5.       (- (* (caddr v1) (car v2)) (* (car v1) (caddr v2)))
  6.       (- (* (car v1) (cadr v2)) (* (cadr v1) (car v2)))
  7.     )
  8.   )
  9.   ;;  http://www.theswamp.org/index.php?topic=22638.msg334208#msg334208  
  10.   ;;  InverseMatrix (gile) 2009/03/17                                    
  11.   ;;  Uses the Gauss-Jordan elimination method to calculate the inverse  
  12.   ;;  matrix of any dimension square matrix                              
  13.   ;;                                                                    
  14.   ;;  Argument : a square matrix                                        
  15.   ;;  Return : the inverse matrix (or nil if singular)                  
  16.   (defun InverseMatrix (mat / col piv row res)
  17.     (defun Imat (d / i n r m)
  18.       (setq i d)
  19.       (while (<= 0 (setq i (1- i)))
  20.         (setq n d)
  21.         (setq r nil)
  22.         (while (<= 0 (setq n (1- n)))
  23.           (if (= i n)
  24.             (setq r (cons 1.0 r))
  25.             (setq r (cons 0.0 r))
  26.           )
  27.         )
  28.         (setq m (cons r m))
  29.       )
  30.     )
  31.     (setq mat (mapcar '(lambda (x1 x2) (append x1 x2)) mat (Imat (length mat))))
  32.     (while mat
  33.       (setq col (mapcar '(lambda (x) (abs (car x))) mat))
  34.       (repeat (vl-position (apply 'max col) col) (setq mat (append (cdr mat) (list (car mat)))))
  35.       (if (equal (setq piv (caar mat)) 0.0 1e-14)
  36.         (progn (setq mat nil) (setq res nil))
  37.         (progn
  38.           (setq piv (/ 1.0 piv))
  39.           (setq row (mapcar '(lambda (x) (* x piv)) (car mat)))
  40.           (setq mat (mapcar '(lambda (r / e) (setq e (car r)) (cdr (mapcar '(lambda (x n) (- x (* n e))) r row)))
  41.                             (cdr mat)
  42.                     )
  43.           )
  44.           (setq res (cons
  45.                       (cdr row)
  46.                       (mapcar '(lambda (r / e) (setq e (car r)) (cdr (mapcar '(lambda (x n) (- x (* n e))) r row))) res)
  47.                     )
  48.           )
  49.         )
  50.       )
  51.     )
  52.     (reverse res)
  53.   )
  54.   (setq ss (ssget ":l"))
  55.   (initget "Points Face")
  56.   (setq al3-var1 (getkword "\n Method : [ Points / Face ] : "))
  57.   (cond
  58.     ((= al3-var1 "Points")
  59.      (command "ucs" "world")
  60.      (setq po1 (getpoint "\n select origin point for new ucs : "))
  61.      (setq po2 (getpoint "\n select point on x-axis of new ucs : " po1))
  62.      (grdraw po1 po2 1 1)
  63.      (setq po3 (getpoint "\n select y-axis direction of new ucs : " po1))
  64.      (grdraw po1 po3 2 1)
  65.      (grdraw po2 po3 3 1)
  66.     )
  67.     ((= al3-var1 "Face")
  68.      (princ "\n Select Face for Top : ")
  69.      (command "ucs" "face" "\\" "")
  70.      (setq po1 (getvar "ucsorg"))
  71.      (setq po2 (mapcar '+ po1 (getvar "ucsxdir")))
  72.      (setq po3 (mapcar '+ po1 (getvar "ucsydir")))
  73.     )
  74.   )
  75.   (setq v12 (list (- (car po2) (car po1)) (- (cadr po2) (cadr po1)) (- (caddr po2) (caddr po1))))
  76.   (setq v13 (list (- (car po3) (car po1)) (- (cadr po3) (cadr po1)) (- (caddr po3) (caddr po1))))
  77.   (setq z (sub1 v12 v13))
  78.   (setq po4 (mapcar '+ po1 (sub1 z v12)))
  79.   (setq nam (strcat (menucmd "M=$(edtime,$(getvar,date),YYYYMODDHHMMSS)") (itoa (abs (getvar "millisecs")))))
  80.   (setq ucsobj (vla-add ucss (vlax-3d-point po1) (vlax-3d-point po2) (vlax-3d-point po4) nam))
  81.   (vla-put-activeucs doc ucsobj)
  82.   (setq TransMatrix (vla-getucsmatrix ucsobj))
  83.   (setq inf (vlax-safearray->list (vlax-variant-value TransMatrix)))
  84.   (setq mat (vlax-tmatrix (InverseMatrix inf)))
  85.   (foreach obj (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
  86.     (vla-transformby obj mat)
  87.   )
  88.   (princ)
  89. )