Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

combine strings into one text or mtext box

4 REPLIES 4
Reply
Message 1 of 5
claycarr
375 Views, 4 Replies

combine strings into one text or mtext box

how can i combine several strings and insert them into a text or mtext box.

string1 "2"
sting2 "beams"

result in text/mtext would be "2 beams"

thanks.
4 REPLIES 4
Message 2 of 5
andrew_nao
in reply to: claycarr

you mean something like this

(DEFUN C:PASTE ()
(SETVAR "CMDECHO" 0)
(SETQ EN1 (CAR (ENTSEL)))
(SETQ EN2 (CAR (ENTSEL)))
(SETQ ED1 (ENTGET EN1))
(SETQ ED2 (ENTGET EN2))
(SETQ ET1 (CDR (ASSOC 1 ED1)))
(SETQ ET2 (CDR (ASSOC 1 ED2)))
(setq testwrd (substr et2 1 3))
(if (= testwrd "%%u") (setq et2 (substr et2 4)))
(if (= testwrd "%%U") (setq et2 (substr et2 4)))
(SETQ ET3 (STRCAT ET1 " " ET2))
(SETQ ED1 (SUBST (CONS 1 ET3) (ASSOC 1 ED1) ED1))
(ENTMOD ED1)
(ENTDEL EN2)

(SETVAR "CMDECHO" 1)
)

EXAMPLE:
line 1 --- hello
line 2 --- there

select hello first then select there second gives you
hello there
Message 3 of 5
claycarr
in reply to: claycarr

that is a nice function but i dont want to select objects. the string is coming from questions given to the user:

how many beams? the user enters "3"
the string "beams" is done for me like this: setq beam "beams" with in the programs.

result = "3 beams"
done with a command "text".....etc.
Message 4 of 5
tader1
in reply to: claycarr

found this here, i modified it a bit.

(defun C:BTX (/ ELEM ETYK CM OS OLDERR PTW PT10 TMP ODL OPIS TBOX ITEM a ab ent ent1 temp1 comb)
(defun FILE:ERROR ()

(command "_undo" "_e")
(setq *ERROR* OLDERR)
(setvar "OSMODE" OS)
(setvar "CMDECHO" CM)
(princ)) ;end file:error

(defun XY (A) (list (car A) (cadr A))) ;end xy

(defun DXF (A B) (cdr (assoc A B))) ;end dxf

(defun STRIM (A)
(while (member (substr A 1 1) (list " " "," "." "-" ";"))
(setq A (substr A 2))
) ;_ end of while
A) ;end strim

(defun PRPT (A B)
(if (not (assoc A ELEM))
(setq ELEM (append ELEM (list (cons A B))))
) ;_ end of if
ELEM
) ;end prpt

(setq OLDERR *ERROR*
*ERROR* FILE:ERROR
ELEM NIL
CM (getvar "CMDECHO")
OS (getvar "OSMODE")
) ;_ end of setq

(setvar "CMDECHO" 0)
(setvar "OSMODE" 0)
(command "_undo" "_be")

(while (setq ETYK (entsel "\n* Pick a Text to Break *"))
(if (and (setq ELEM (entget (car ETYK))) (eq (DXF 0 ELEM) "TEXT"))
(progn
(setq PTW (XY (trans (cadr ETYK) 1 0)))
(command "_ucs" "_ob" (car ETYK))
(setq PTW (trans PTW 0 1)
OPIS (DXF 1 ELEM)
ITEM 1
TEMP 0.0
) ;_ end of setq
(while
(or
(not (member (substr OPIS ITEM 1) (list "" " ")))
(< TEMP (car PTW))
) ;_ end of or
(setq TBOX (textbox (subst (cons 1 (substr OPIS 1 ITEM)) (assoc 1 ELEM) ELEM)) ;_ end of textbox
TEMP (- (caadr TBOX) (caar TBOX))
ITEM (1+ ITEM)
) ;_ end of setq
) ;end while
(entmod (subst (cons 1 (substr OPIS 1 (1- ITEM))) (cons 1 OPIS) ELEM))
(setq A (append A (list '(62 . 4))))
(PRPT 62 256)
(PRPT 6 "BYLAYER")
(setq ab (subst (cons 1 (STRIM (substr OPIS (1+ ITEM)))) (cons 1 OPIS) ELEM)) ;_ end of entmake

;(command "_move" (entlast) "" "0,0" (list 0 (- (* 1.4 (DXF 40 ELEM))))) ;_ end of command
(setq ent (entsel "\nSelect prepending text line or to create new line: "))
(if ent
(progn
(setq ent (entget (car ent))
ent1 (cdr (assoc 1 ent))
temp1 (cdr (assoc 1 ab))
comb (strcat temp1 " " ent1))
(entmod (subst (cons 1 comb)(assoc 1 ent) ent))
)
(progn
(entmake
(subst (cons 1 (STRIM (substr OPIS (1+ ITEM)))) (cons 1 OPIS) ELEM)) ;_ end of entmake
(command "_move" (entlast) "" "0,0" (list 0 (- (* 1.7143 (DXF 40 ELEM))))) ;_ end of command
))
(command "_ucs" "_p")
(command "_undo" "_e")
(setq *ERROR* OLDERR)
(setvar "OSMODE" OS)
(setvar "CMDECHO" CM)
(princ)
) ;_ end of defun
)))
Message 5 of 5
claycarr
in reply to: claycarr

I just figured it out, thanks for the help, i liked that lisp

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost