textbox edit command append text

textbox edit command append text

Anonymous
Not applicable
1,244 Views
4 Replies
Message 1 of 5

textbox edit command append text

Anonymous
Not applicable

I want to be able to execute a command that will alter a single textbox that I click on to append the text "(E)" to the beginning of the text inside the textbox.  I thought it would be simple but I'm having a hard time finding the resources I need to figure this out.  So far I don't see the needed commands to do this.  Please don't suggest alternative ways of doing the work, I want to create this custom command and use it as a command in AutoCAD MEP 2016 on single text boxes.  Thanks for in advance for all useful help.

0 Likes
Accepted solutions (1)
1,245 Views
4 Replies
Replies (4)
Message 2 of 5

Keith.Brown
Advisor
Advisor
Accepted solution

I found this LISP program by LEE MAC at http://www.cadtutor.net/forum/archive/index.php/t-27204.html that does what you want.

 

(defun c:pretxt (/ pos txt ent en enlist txtval)
(setvar "cmdecho" 0)
(initget 1 "Prefix Suffix")
(setq pos (getkword "\nSelect Position [Prefix/Suffix]"))
(setq txt (getstring "\nType Prefix/Suffix: "))
(if (setq ent (entsel "\nSelect Text: " ))
(progn
(while (/= nil ent)
(if (setq en (car ent))
(progn
(setq enlist (entget en))
(setq txtval (cdr (assoc 1 enlist)))
(cond
((= pos "Prefix")
(setq txtval (strcat txt " " txtval))
) ; end condition 1
(( = pos "Suffix")
(setq txtval (strcat txtval " " txt))
) ; end condition 2
) ; end cond
(setq enlist (subst (cons 1 txtval)(assoc 1 enlist)enlist))
(entmod enlist)
(entupd en)
)
)
(setq ent (entsel "\nSelect Text: "))
) ; end while
)
(alert "Please Select Text")
)
(setvar "cmdecho" 1)
(prompt "\nFunction Complete")
(princ)
)

 

You could automate it further by hard coding in the prefix selection and the text to prefix with.

 

If you have never ran an AutoLisp program then you can look here.  http://www.lee-mac.com/tutorials.html#lisptutorials

 

0 Likes
Message 3 of 5

Anonymous
Not applicable
When I run the command (I saved scr files using notepad and then ran using the run script button) I get this in the command line nothing else seems to happen. Sorry I'm new to this but I have been doing a lot of reading and watching a video.

(_> ); end of c:ftxt

Am I doing something wrong?

Tim Burke

T.E., Inc.
830 North Riverside Drive #200
Renton, WA. 98057
(425) 970-3753 Phone
(425) 970-3756 Fax
WWW.TEI-ENGINEERING.COM
This message contains information that is confidential or privileged. The information is intended for the use of the individual or entity named above. If you are not the intended recipient, be aware that any disclosure, copying, distribution or use of the contents of this information is prohibited. If you have received this electronic transmission in error, please notify the sender and delete this message and any attachments
0 Likes
Message 4 of 5

Keith.Brown
Advisor
Advisor

Yes,  This is a LISP program, it is not a script file.  Please follow the last link i published on how to run LISP files.

 

Basically you just past the text into a file with a .lsp extension.  You can then drag that file inside of model space to load the lisp file.  You then have access to the command list in the lisp file.

0 Likes
Message 5 of 5

Anonymous
Not applicable

Thanks for the help.  I have been studying and I was able to modify one of the scripts to get rid of the prompts that I don’t need and it works now.  Now I’m trying to upgrade to a routine that inserts blocks quickly and specifies the position, layer, and rotation.  I would actually like to have a separate command, and a button for each specific block.  A couple examples are:

 

A T symbol for a water line.  Very simple block with 3 lines.  I would like to be able to press a key combination with the left hand or press a button, then press 1 of 4 keys to specify the layer, then 1 of 4 keys to specify the rotation (0,90,180,270).  I’m guessing this has already been done and someone can point me to a program that I can customize.

 

Thanks again..

0 Likes