;Tip1556: TR.LSP Text Rotate (C)1999, William E. Barlow ;Published in Cadalyst Magazine September 1999 issue in the Hot Tip Harry Section :http://cadtips.cadalyst.com/node/tiplisting?keywords=Tip1556 ; This LISP routine allows the user to select a line (Not a pline) ; and then select text (Not MText) and the text rotates to the ; angle of the line (defun C:TR () (setvar "CMDECHO" 0) (prompt "\nSelect Line: ") ; select object line (setq LINE (ssget)) ; get selection set of line (setq INDEX 0) ; establish an index (setq ENAME (ssname LINE INDEX)) ; give a name to the line (setq ELIST (entget ENAME)) ; create a list (setq PT1 (cdr (assoc 10 ELIST))) ; get end pt1 x,y,z values from set (setq VALUE11 (car PT1)) ; get x coordinate pt1 (setq VALUE12 (cadr PT1)) ; get y coordinate pt1 (setq VALUE13 (caddr PT1)) ; get z coordinate pt1 (setq PT2 (cdr (assoc 11 ELIST))) ; get end pt2 x,y,z values (setq VALUE21 (car PT2)) ; get x coordinate pt2 (setq VALUE22 (cadr PT2)) ; get y coordinate pt2 (setq VALUE23 (caddr PT2)) ; get z coordinate pt2 (setq LANGLE (angle PT1 PT2)) ; get angle of selected lline (setq P12 (/ pi 2.0)) ; do calcs (setq P32 (* pi 1.5)) (setq P2 (* pi 2.)) (if (and (>= LANGLE 0.0) (<= LANGLE P12)) (setq NARCTAN LANGLE)) (if (and (>= LANGLE P32) (<= LANGLE P2)) (setq NARCTAN LANGLE)) (if (and (>= LANGLE P12) (<= LANGLE pi)) (setq NARCTAN (+ LANGLE pi))) (if (and (>= LANGLE pi) (<= LANGLE P32)) (setq NARCTAN (- LANGLE pi))) (prompt "\nSelect Text: ") ; select object text (setq TEXTL (entget (car (entsel)))) ; get selection set of text (setq OTEXT (assoc 50 TEXTL)) ; get value from set (setq NTEXT (cons 50 NARCTAN)) ; concatentate (setq TEXTL (subst NTEXT OTEXT TEXTL)) (entmod TEXTL)) ; Modify the definition data of an object (entity)