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.
Solved! Go to Solution.
Solved by Keith.Brown. Go to 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
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.
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..