Author Topic: first lisp, only working in wcs  (Read 1884 times)

0 Members and 1 Guest are viewing this topic.

DraxJDM

  • Newt
  • Posts: 47
first lisp, only working in wcs
« on: June 10, 2011, 09:54:04 AM »
Hey all,

this lisp take's the rotation of a block, the rotate a text to the same rotation, -90°
if text is upsidedown then ratote 180°

only works good if i am in wcs

can some one tell me how do i use "trans" ?  are a ontherway

Thx JOhn
Code: [Select]
(defun c:MRot (/ ) ;


(and
 (setq Sel1 (entsel "\n Select object with desired rotation: "))
 (setq Sel2 (entsel "\n Select object to change rotation: "))


(setq rot1 (vla-get-Rotation (vlax-ename->vla-object (car Sel1))))
 
(setq rot2 (- rot1 1.57079633)) ;  rotate 90

(if (or
        (<= rot2 -1.57079633)
        (> rot2 1.57079633)
     ); end  and
  (setq rot3 (- rot2 3.14159266)); if ok
  (setq rot3 rot2); if not ok
); end if   

(vla-put-Rotation (vlax-ename->vla-object (car Sel2)) rot3)
)


(princ)
)

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: first lisp, only working in wcs
« Reply #1 on: June 10, 2011, 10:52:58 AM »
Carefully study this code:

Code: [Select]
(defun c:mrot ( / sel1 sel2 sel1-e sel1-r sel2-e ucsx-a ucsx-u ucsx-w ucsz-w )
  (if
    (and
      (setq sel1 (car (entsel "\nSelect Object With Desired Rotation: ")))
      (member (cdr (assoc 0 (entget sel1))) '("TEXT" "MTEXT" "INSERT"))
     
      (setq sel2 (car (entsel "\nSelect Object to Change Rotation: ")))
      (member (cdr (assoc 0 (entget sel2))) '("TEXT" "MTEXT" "INSERT"))
    )
    (progn
      (setq ucsx-w (getvar 'UCSXDIR))
[color=green]      ;; This returns the UCS X-Vector relative to WCS[/color]

      (setq ucsz-w (trans '(0. 0. 1.) 1 0 t))
[color=green]      ;; This returns the UCS Z-Vector (normal) relative to WCS[/color]

      (setq ucsx-u (trans ucsx-w 0 ucsz-w))
[color=green]      ;; This returns the UCS X-Vector relative to UCS[/color]

      (setq ucsx-a (angle '(0. 0. 0.) ucsx-u))
[color=green]      ;; This returns the angle formed by the UCS X-Vector and the vector '(1. 0. 0.)[/color]

      (setq sel1-e (entget sel1))
[color=green]      ;; DXF Data of first entity[/color]

      (setq sel1-r (cdr (assoc 50 sel1-e)))
[color=green]      ;; Rotation of first entity[/color]

      (if (eq (cdr (assoc 0 sel1-e)) "MTEXT")
        (setq sel1-r (+ sel1-r ucsx-a))
      )
[color=green]      ;; MText rotation property is relative to UCS[/color]

      (setq sel1-r (- sel1-r (/ pi 2.)))
[color=green]      ;; Rotation by pi/2 clockwise[/color]

      (setq sel2-e (entget sel2))
[color=green]      ;; DXF Data of second entity[/color]

      (if (eq (cdr (assoc 0 sel2-e)) "MTEXT")
        (setq sel1-r (- sel1-r ucsx-a))
      )
[color=green]      ;; MText rotation property is relative to UCS[/color]

      (if (and (< (/ pi 2.) sel1-r) (<= sel1-r (/ (* 3. pi) 2.)))
        (setq sel1-r (- sel1-r pi))
      )
[color=green]      ;; Correct Rotation for readability[/color]

      (setq sel2-e (subst (cons 50 sel1-r) (assoc 50 sel2-e) sel2-e))
[color=green]      ;; Substitute the group 50 dotted pair in the DXF Data[/color]

      (entmod sel2-e)
[color=green]      ;; Update the Drawing database.[/color]
    )
  )
  (princ)
)

DraxJDM

  • Newt
  • Posts: 47
Re: first lisp, only working in wcs
« Reply #2 on: June 10, 2011, 12:11:57 PM »
thx Lee, i'm gonna take a good look at it ...


greetz JOhn

not native english

DraxJDM

  • Newt
  • Posts: 47
Re: first lisp, only working in wcs
« Reply #3 on: June 10, 2011, 12:14:21 PM »
the first object i normaly pick is a block  ..

so think i that i have change the first select object

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: first lisp, only working in wcs
« Reply #4 on: June 10, 2011, 04:14:53 PM »
Hi,

You can read this thread.
Speaking English as a French Frog

DraxJDM

  • Newt
  • Posts: 47
Re: first lisp, only working in wcs
« Reply #5 on: June 10, 2011, 04:57:28 PM »
thx gille

very intresting, i'm working 4 years with cad and never had heard about ocs.
only wcs and ucs ...

i'm gonna have to learn a lot, to get lisp working for me.



Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: first lisp, only working in wcs
« Reply #6 on: June 10, 2011, 06:14:42 PM »
the first object i normaly pick is a block  ..

so think i that i have change the first select object

You're welcome John :-)

Note that my above code will allow a block to be selected as the first object.