Align Text

Discussion in 'AutoCAD' started by John, Jun 9, 2004.

  1. John

    John Guest

    I was trying to write a lisp to align text but something wrong in this lisp.
    Also I have no idea how to handle (if (= "text","mtext" (cdr b)).

    (defun c:talign ()
    (setq gp (getpoint "\nSpecify a point:"))
    (setq gx (car gp))
    (prompt "\nSelect text to align")
    (setq gt (setq gt (ssget '((0 . "MTEXT,TEXT" )))))
    (setq n (sslength gt))
    (setq index 0)
    (repeat n
    (setq b1 (entget (ssname gt index)))
    (setq index (index+ 1))
    (setq b (assoc 0 b1))
    (if (= "text" (cdr b))
    (progn
    (setq c (cadr (assoc 10 b1)))
    (setq b2 (subst gx c))
    (entmod b2)
    )
    )
    )
    (princ)
    )
    (princ)

    Thanks

    John
     
    John, Jun 9, 2004
    #1
  2. John

    bruno Guest

    John a écrit :
    (if (or (= "TEXT" (cdr b)) (= "MTEXT" (cdr b))) ... )
     
    bruno, Jun 9, 2004
    #2
  3. John

    Paul Turvill Guest

    Here are the errors I see at a quick glance:

    Change
    (setq gt (setq gt (ssget '((0 . "MTEXT,TEXT" )))))
    to
    (setq gt (ssget '((0 . "MTEXT,TEXT"))))

    Change
    (setq index (index+ 1))
    to
    (setq index (1+ index))

    You don't need any (if ...) statements to test for TEXT or MTEXT objects,
    since your selection set was filtered for only those object types when it
    was created.
    There may be other errors in logic, as well, but these fixes may get you on
    the right path.
    ___
     
    Paul Turvill, Jun 9, 2004
    #3
  4. John

    Paul Turvill Guest

    Right. But he really doesn't need the (if ...) statement at all, since his
    selection contains *only* TEXT and MTEXT objects in the first place.
    ___
     
    Paul Turvill, Jun 9, 2004
    #4
  5. John

    T.Willey Guest

    Here is one I use, you may have to change it a little to work the way you want it to. I select a peace of text to line up all the other peaces of text I pick.

    Code:
    (defun c:lu()
    
    (command "undo" "group")
    
    (setvar "errno" 0)
    (setq al1 nil)
    (while (and (/= 52 (getvar "errno")) (not al1))
    (initget "X Y")
    (setq al1(nentsel "\nSelect master text to align along X axis or <\"Y\"> to align along Y axis:  "))
    )
    (if (or (= al1 "y") (= al1 "Y"))
    (progn
    (setq al1 nil)
    (while (and (/= 52 (getvar "errno")) (not al1))
    (setq al1 (nentsel "\nSelect master text to align along Y axis:  "))
    )
    (setq tset0 al1)
    (setq al1 "y")
    )
    (progn
    (setq tset0 al1)
    (setq al1 "x")
    )
    )
    
    (if (= tset0 nil)
    (vl-exit-with-value nil)
    (progn
    (setq tset1 (entget (car tset0)))
    (redraw (cdr (assoc -1 tset1)) 3)
    (setq al2 (cdr (assoc 72 tset1)))
    (setq al3 (cdr (assoc 73 tset1)))
    (if (and (= al2 0) (= al3 0))
    (progn
    (setq alx (cadr(assoc 10 tset1)))
    (setq aly (caddr(assoc 10 tset1)))
    )
    (progn
    (setq alx (cadr(assoc 11 tset1)))
    (setq aly (caddr(assoc 11 tset1)))
    )
    )
    )
    )
    
    (setq tset2 (ssget '((0 . "TEXT"))))
    (if (= tset2 nil)
    (progn
    (setq tlng1 0)
    (redraw (cdr (assoc -1 tset1)) 4)
    )
    (setq tlng1 (sslength tset2))
    )
    (setq tlng2 0)
    
    (repeat tlng1
    (progn
    (setq tset3 (ssname tset2 tlng2))
    (setq tset4 (entget tset3))
    (setq al4 (cdr (assoc 72 tset4)))
    (setq al5 (cdr (assoc 73 tset4)))
    (if (and (= al4 0) (= al5 0))
    (progn
    (setq al6 (cdr (assoc 10 tset4)))
    (cond
    ((= al1 "x")
    (setq al6 (subst alx (car al6) al6))
    )
    ((= al1 "y")
    (setq al6 (subst aly (cadr al6) al6))
    )
    )
    (setq tset4 (subst (cons 10 al6) (assoc 10 tset4) tset4))
    (redraw (cdr (assoc -1 tset1)) 4)
    )
    (progn
    (setq al6 (cdr (assoc 11 tset4)))
    (cond
    ((= al1 "x")
    (setq al6 (subst alx (car al6) al6))
    )
    ((= al1 "y")
    (setq al6 (subst aly (cadr al6) al6))
    )
    )
    (setq tset4 (subst (cons 11 al6) (assoc 11 tset4) tset4))
    (redraw (cdr (assoc -1 tset1)) 4)
    )
    )
    (entmod tset4)
    (setq tlng2 (1+ tlng2))
    )
    )
    
    (command "undo" "end")
    (princ)
    
    )
    
    Tim
     
    T.Willey, Jun 9, 2004
    #5
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.