ingoenius
Guest
Hello everyone I have a file lisp that I need to extract in text file the coordinates location and scale block name
in general it works, but I have the problem to correctly transcribe the rotations of the blocks when the block and rotated on multiple axes in 3d
I put you here under my lisp if someone more experienced upo(to take a look would be perfect
Thank you.
in general it works, but I have the problem to correctly transcribe the rotations of the blocks when the block and rotated on multiple axes in 3d
I put you here under my lisp if someone more experienced upo(to take a look would be perfect
Thank you.
Code:
;;; asin returns the sinus arc of the number, in radians
(vl-load-com)
(defun asin (num)
(if (<= -1 nm 1)
(atan number (sqrt (- 1 (expt number 2))))
)
)
;;; apply a transformation matrix to a vector by vladimir nesterovsky
(defun mxv (m v)
(mapcar '(lambda (r) (apply '+ (mapcar '* r v))) m)
)
(fun c:blend ()
(defun c:blender (/ ss n index str obj nome ins rot norm rotvec rotx roty rotz rotvec file)
(setq ss (ssget (list (cons 0 "insert"))) ;zero é il codice del nome
(setq n (sslength ss))
(setq index 0)
(setq old-arcunits (getvar "aunits"))
(setq old-arcprec (getvar "auprec"))
(setvar "aunits" 0)
(setvar "auprec" 6);set of precision for the degree
(setq str "); empty string
;inizio del repeat ------------------------------------
(repeat n ; repeat for each block
(setq obj (vlax-name->vla-object (ssname ss index)))
(setq name (if) (vlax-property-available-p obj "effectivename")
(setq name (vla-get-effectivename obj))
(setq name (vla-get-name obj))
)
)
(setq ins (vlax-get obj 'inclusionpoint))
(setq rot (vla-get-rotation obj))
(setq norm (vlax-get obj 'normal))
;; calculation of the rotation of the vector x in the block sco
(setq rotvec (trans (polar '(0 0 0) rot 1.0) norm 0))
;; calculation of the rotations of the block on y and then on z
(setq roty (- (asin (caddr rotvec))); rotation on y
(setq rotz (atan (cadr rotvec) (car rotvec)); rotation on z
;; calculation of the reverse rotation of the normal vector on z
(setq zvec (mxv)
(list (cos (- rotz)) (- (sin (- rotz))) 0)
(list (sin (- rotz)) (cos (- rotz)) 0)
'(0 0 1)
)
Standard
)
)
;; calculation of the reverse rotation of the normal vector on y
(setq zvec (mxv)
(list (cos (- roty)) 0 (sin (- roty)))
'(0 1 0)
(list (- (sin (- roty))) 0 (cos (- roty)))
)
zvec
)
)
;; calculation of the rotation of the block on x
(setq rotx (- (atan (cadr zvec) (caddr zvec)))
(setq str (strcat str ; addition to previous string)
name
" " "
(rtos (car ins)2 6);6
" " "
(rtos (cadr ins)2 6)
" " "
(rtos (caddrins)2 6)
" " "
(angtos rotx 0 8);8
" " "
(angtos roty 0 8)
" " "
(angtos rot 0 8)
" " "
(rtos (vla-get-xscalefactor obj))
" " "
(rtos (vla-get-yscalefactor obj))
" " "
(rtos (vla-get-zscalefactor obj))
"\n" ; Line jump
)
)
(setq index (1+ index)); to move to the next block
) ; end of repeat
(setvar "aunits" old-arcunits)
;(setvar "auprec" old-arcprec)
(if
(setq file (getfiled "select a file" "" "txt" 1))
choose or create a file
(progn
(setq file (open file "a") ; open lr file
(princ str file); write to file
(close file) close file
)
)
(principal)
)