Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Distinguished Contributor
claycarr
Posts: 325
Registered: ‎02-06-2004
Message 1 of 5 (99 Views)

combine strings into one text or mtext box

99 Views, 4 Replies
11-16-2006 07:41 AM
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.
Distinguished Contributor
andrew_nao
Posts: 1,419
Registered: ‎06-03-2002
Message 2 of 5 (99 Views)

Re: combine strings into one text or mtext box

11-16-2006 07:56 AM in reply to: claycarr
you mean something like this

(DEFUN C:smileytongue:ASTE ()
(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
Distinguished Contributor
claycarr
Posts: 325
Registered: ‎02-06-2004
Message 3 of 5 (99 Views)

Re: combine strings into one text or mtext box

11-16-2006 08:11 AM 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.
Distinguished Contributor
tader1
Posts: 319
Registered: ‎11-01-2004
Message 4 of 5 (99 Views)

Re: combine strings into one text or mtext box

11-16-2006 08:15 AM 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
)))
Distinguished Contributor
claycarr
Posts: 325
Registered: ‎02-06-2004
Message 5 of 5 (99 Views)

Re: combine strings into one text or mtext box

11-16-2006 08:16 AM in reply to: claycarr
I just figured it out, thanks for the help, i liked that lisp

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community