• This forum is the machine-generated translation of www.cad3d.it/forum1 - the Italian design community. Several terms are not translated correctly.

problem transcription rotation blocks with extraction info

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.

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)
)
 
call back the function by passing the name entity <n> and the <tipo> result you want me to come back.
then to get the three axes of rotation, recalls the function 3 times:
(setq rotxy (fnbloccorot n "xy")
(setq rotxz)
(setq rotyz)

greetings

this is the function:
; blocks built with extruded entities according to the z axis of ucs world
; n: entity name; type: "xy" (rotation piano xy), "xz" (rotation piano xz), "yz" (rotation piano yz)
(defun fnbloccorot(n type / rot ent x y z pt)
(setq ent)
(setq pt (cdr (assoc 210 ent)))
(setq x (car pt))
(setq y) (cadr pt)
(Sectq z)
(cond)
((= type "xy") (setq rot (cdr))))
((= type "xz") (setq rot (angle (list 0 0 0) (list x z 0.0)))))
((= type "yz") (setq rot (angle (list 0 0 0) (list y z 0.0)))))
)
; from radiants to sessadecimali
(setq rot (*(/ 180.0 pi) rot))
; function returns the conversion in real number of the angle string with precision to 6 decimals
; used to round the measure to 6 decimal
(atof (rtos rot 2 6)
)</tipo></n>
 

Forum statistics

Threads
44,997
Messages
339,767
Members
4
Latest member
ibt

Members online

No members online now.
Back
Top