Append text

Discussion in 'AutoCAD' started by winnro, May 27, 2004.

  1. winnro

    winnro Guest

    I need a lisp that will append text with other text to make one piece of text.

    Example:
    You have "joe" as one text item and "smith" as another text item. I would like a routine to merge these into "joe smith" or "joesmith".
     
    winnro, May 27, 2004
    #1
  2. winnro

    C Witt Guest

    ET: txt2mtxt
     
    C Witt, May 27, 2004
    #2
  3. winnro

    T.Willey Guest

    (defun c:adt ()

    (command "undo" "group")

    (if (not *str1) (setq *str1 "_"))
    (princ "\nEnter string to insert <")(princ *str1)
    (setq str1 (getstring T ">: "))
    (if(= str1 "")(setq str1 *str1)(setq *str1 str1))
    (initget "Prefix Suffix")
    (setq str2(getkword"\nSelect type of insertion Prefix/<Suffix>:"))
    (if(not str2)(setq str2 "Suffix"))
    (prompt"\nSelect string(s) to edit: ")
    (setq p (ssget '((0 . "*TEXT"))))
    (setq n (sslength p))
    (setq l 0)
    (setq t 1)
    (setq newtxt nil)
    (while (/= l n)
    (setq ed (entget (ssname p l)))
    (setq ovalue (cdr(assoc 1 ed)))
    (cond
    ((= str2 "Suffix")(setq cvalue (strcat ovalue str1))
    )
    ((= str2 "Prefix")(setq cvalue (strcat str1 ovalue))
    ))
    (setq bn (subst(cons 1 cvalue)(assoc 1 ed) ed))
    (entmod bn)
    (setq l (+ l 1))
    )
    (command "undo" "end")
    (princ)

    )

    Here is one I use. It works for me, but if you want something a little different then you can tweak a few parts.

    Tim
     
    T.Willey, May 27, 2004
    #3
  4. winnro

    winnro Guest

    Thanks a lot Tim.

    Rob
     
    winnro, May 27, 2004
    #4
  5. winnro

    T.Willey Guest

    No problem. Just hope it helps. I've gotten so much help from this group, it just feels good to help some other people.

    Tim
     
    T.Willey, May 27, 2004
    #5
  6. NOTE - there is NO error checking to make sure that the entities are text or
    mtext.

    ;ADDT = combine line(s) of text to 1st line of text selected
    (defun C:ADDT (/ ES1 EG1 TT ES2 EG2)
    (setq ES1 (entsel "\nSelect 1st Line of Text to Combine ? "))
    (while ES1
    (setq EG1 (entget (car ES1)))
    (setq TT (cdr (assoc 1 EG1)))
    (setq ES2 (entsel "\nSelect Text to combine ? "))
    (while ES2
    (setq EG2 (entget (car ES2)))
    (setq TT (strcat TT " " (cdr (assoc 1 EG2))))
    (entdel (cdr (assoc -1 EG2)))
    (setq ES2 (entsel "\nSelect another Line of Text to combine ? "))
    )
    (setq EG1 (subst (cons 1 TT) (assoc 1 EG1) EG1))
    (entmod EG1)
    (setq ES1 (entsel "\nSelect next 1st Line of Text to Combine ? "))
    )
    (princ)
    )
     
    Alan Henderson @ A'cad Solutions, May 28, 2004
    #6
  7. winnro

    winnro Guest

    Excellent.

    Thanks Alan.

    Rob
     
    winnro, May 28, 2004
    #7
  8. winnro

    devitg Guest

    Why not it ???
    (Setq text1 "joe")
    (setq text2 "smith")
    (setq newtext ( strcat text1 " " text2))
     
    devitg, May 30, 2004
    #8
  9. winnro

    ECCAD Guest

    devitg,
    I think he meant to (strcat) some existing text, and replace
    text1 with (strcat text1 text2)..

    Bob
     
    ECCAD, May 30, 2004
    #9
  10. winnro

    Adesu Guest

    Hi winnro,check my code and try it,and more simple,then you can learn it

    ; ato is stand for add text from others text
    ; Design by Ade Suharna <>
    ; 29 October 2004
    ; program no. 129/10/2004
    ; edit by
    (defun c:ato (/ ent info1 opt info1opt adtex)
    (while
    (setq ent (entget (car (entsel "\nSELECT A SOURCE TEXT: "))))
    (setq info1 (cdr (assoc 1 ent)))
    (while
    (setq opt (entget (car (entsel "\nSELECT A TEXT WOULD TO CHANGE: "))))
    (setq info1opt (cdr (assoc 1 opt)))
    (setq adtex (strcat info1opt " " info1))
    (entmod
    (subst (cons 1 adtex)(assoc 1 opt) opt))
    )
    (princ)
    )
    )


    like a routine to merge these into "joe smith" or "joesmith".
     
    Adesu, Jan 6, 2005
    #10
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.