You are on page 1of 3

;;;CADALYST 07/04 Tip1964: TS.

LSP Text spacing (c) 2004 Tracey Richmond

;This program will take a series of text strings, selected individually


;and in sequence, and revise the spacing between each line. It doesn't
;matter what the justification is, as long as all justifications for picked
;text is the same. Also, it uses the text height of the FIRST selected text
;as the multiplier, so it helps if the group of text you are aligning is the same
height.
;
;----------------------------------
;Error handler
(defun MYERR (MSG)
(if (and (/= MSG "Function cancelled") (/= MSG "console break"))
(progn
(princ "\nError: ")
(princ MSG)
)
)
(setq *error* OLDER)
(setvar "cmdecho" 0)
(princ)
)
;---------------------------
;
(defun c:TS (/ older tmpdis ss sslen ctr ent txtrot just code inspt
xpt ypt entlis tdisp x y pt theta height dis)
(setvar "cmdecho" 0)
(command ".undo" "m")
(setq older *error*
*error* myerr
)
(princ "\nSelect text strings to align in sequence: ")
(setq ss (ssget)
sslen (sslength ss)
ctr 0 ;initialize counter
);close setq
(while (and (/= ss nil) (>= sslen 0) (< ctr sslen))
(setq ent (ssname ss ctr))
(if (= ctr 0)
(progn
(setq txtrot (cdr (assoc 50 (entget ent)))
just (cdr (assoc 72 (entget ent)))
height (cdr (assoc 40 (entget ent)))
)
(setq dis (* height 1.619033))
(if (> just 0)
(setq code 11) ;non-left justified
(setq code 10) ;left justified
)
(setq inspt (cdr (assoc code (entget ent)))
xpt (car inspt)
ypt (cadr inspt)
);close setq
);close progn

(progn
;------------------------------------------------------------------------
;use group code 10 for left justified text.
;All others we will use group code 11, this
;will maintain justification
;---------------------------------------------------

(cond
( (< txtrot (* 0.5 pi)) ;if rotation angle <90 deg
(setq entlis (entget ent)
just (cdr (assoc 72 entlis))
)
(if (> just 0)
(setq code 11)
(setq code 10)
)
(setq tdisp (* ctr dis)
x (+ xpt (* tdisp (sin txtrot)))
y (- ypt (* tdisp (cos txtrot)))
pt (list x y)
entlis (subst (cons code pt) (assoc code entlis) entlis)
);close setq
(entmod entlis)
);close 1st cond

( (and (< txtrot pi) (>= txtrot (* 0.5 pi))) ;if rotation angle
<180 & >= 90 deg
(setq entlis (entget ent)
theta (- txtrot (* 0.5 pi))
tdisp (* ctr dis)
x (+ xpt (* tdisp (cos theta)))
y (+ ypt (* tdisp (sin theta)))
pt (list x y)
entlis (subst (cons code pt) (assoc code entlis) entlis)
);close setq
(entmod entlis)
);close 2nd cond

( (and (< txtrot (* 1.5 pi)) (>= txtrot pi)) ;if rot angle <270 &
>= 180 deg
(setq entlis (entget ent)
theta (- txtrot pi)
tdisp (* ctr dis)
x (- xpt (* tdisp (sin theta)))
y (+ ypt (* tdisp (cos theta)))
pt (list x y)
entlis (subst (cons code pt) (assoc code entlis) entlis)
);close setq
(entmod entlis)
);close 3rd cond

( (and (< txtrot (* 2.0 pi)) (>= txtrot (* 1.5 pi))) ;if rot angle
<360 & >= 270 deg
(setq entlis (entget ent)
theta (- txtrot (* 1.5 pi))
tdisp (* ctr dis)
x (- xpt (* tdisp (cos theta)))
y (- ypt (* tdisp (sin theta)))
pt (list x y)
entlis (subst (cons code pt) (assoc code entlis) entlis)
);close setq
(entmod entlis)
);close 4th cond
);close cond text rotation angles
;-------------------------------------------------------------------------
);close progn
);close if
(setq ctr (1+ ctr)) ;increment counter
);close while
(setvar "cmdecho" 0)
(setq *error* older)
(princ)
)
(princ)

You might also like