Author Topic: Text Align Lisp  (Read 6324 times)

0 Members and 1 Guest are viewing this topic.

hudster

  • Gator
  • Posts: 2848
Text Align Lisp
« on: July 28, 2004, 08:20:06 AM »
I downloaded this lisp from the Cadalyst July code, and it works if you have dtext, but not with mtext, any ideas on how to get this to work with mtext as well as it would make aligning notes so much easier.

Code: [Select]
;;;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)
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

hendie

  • Guest
Text Align Lisp
« Reply #1 on: July 28, 2004, 08:35:00 AM »
if'n'you can hold on for a few.... I may have something for you
I'll let you know

ELOQUINTET

  • Guest
Text Align Lisp
« Reply #2 on: July 28, 2004, 12:24:56 PM »
yeah i was looking at that too but discarded it for the same reason. i would like to use it to align my leaders.

hendie

  • Guest
Text Align Lisp
« Reply #3 on: July 30, 2004, 03:20:36 AM »
Unfortunately, the routine I had in mind doesn't do what you want.
However, I noticed a few "flaws" in the lisp you posted above, namely, if the text objects have different rotations, the lisp doesn't take that into account, the same applies if the text is different heights, or on different layers.
I have a routine that applies the correct rotation, layer and text height to each text object as they are selected. I'll need to upload it for you. I can't do it here while I'm at work so I'll try and do it this evening.

hendie

  • Guest
Text Align Lisp
« Reply #4 on: July 30, 2004, 04:09:04 AM »
one possible workaround at the moment would be to explode the mtext first, then run the lisp which would then align the objects. Then if need be, you could use Txt2Mtxt after to recompile the Mtext.
or even just explode the mtext, use text2mtext and the text will be aligned then anyway