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

0 Members and 1 Guest are viewing this topic.

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: 12914
  • 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. )