Nick-1971 Posted August 14, 2012 Share Posted August 14, 2012 Hello, I have seen a lots of posts regarding adding Prefix and Suffix to mulitple text items , i have just updated to 2012 and have lost my previous program. Can anyone help? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 14, 2012 Share Posted August 14, 2012 Welcome to CADTutor Nick Would this function help you at all? Quote Link to comment Share on other sites More sharing options...
Nick-1971 Posted August 14, 2012 Author Share Posted August 14, 2012 I need to edit around 1700 pieces of tree text so that they have the prefix G: and the suffix M, its not an uncommon thing for me to do so i thought that there must be away of doing it globally? Quote Link to comment Share on other sites More sharing options...
ReMark Posted August 14, 2012 Share Posted August 14, 2012 Did you check out Lee's lisp routine? Quote Link to comment Share on other sites More sharing options...
Nick-1971 Posted August 14, 2012 Author Share Posted August 14, 2012 Might be making a complete muppet of myself but i cant see any other information on thread? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 14, 2012 Share Posted August 14, 2012 Did you view the link I provided? (click on the word 'this' in my earlier post) Quote Link to comment Share on other sites More sharing options...
Nick-1971 Posted August 14, 2012 Author Share Posted August 14, 2012 Thats great thanks, how do i chnage this to have the command word as an option in the drop down menu? Quote Link to comment Share on other sites More sharing options...
Nick-1971 Posted August 14, 2012 Author Share Posted August 14, 2012 How can i make the prefix and suffix user defined? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 14, 2012 Share Posted August 14, 2012 How can i make the prefix and suffix user defined? Use the getstring function to prompt the user for the prefix/suffix, e.g.: (defun c:test ( ) (pstext (getstring t "\nSpecify Prefix <none>: ") (getstring t "\nSpecify Suffix <none>: ") 1) ) 1 Quote Link to comment Share on other sites More sharing options...
CAD Diva Posted June 17, 2020 Share Posted June 17, 2020 @Lee Mac I am not familiar with lisp routines but am willing to try this one because I am desperate. I have to add a prefix to over 30,000 text objects so this will help immensely. However, I cannot decipher where to put what. Can you give me the lisp that will do the following? Select multiple text by drawing polygon(s) on the drawing When running the lisp routine allow me to enter the prefix text whenever I run it Thank you. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 17, 2020 Share Posted June 17, 2020 31 minutes ago, CAD Diva said: I am not familiar with lisp routines but am willing to try this one because I am desperate. I have to add a prefix to over 30,000 text objects so this will help immensely. However, I cannot decipher where to put what. Can you give me the lisp that will do the following? Select multiple text by drawing polygon(s) on the drawing When running the lisp routine allow me to enter the prefix text whenever I run it Using the code found here, you can define a program such as the following: (defun c:pretext ( / p ) (if (/= "" (setq p (getstring t "\nSpecify prefix: "))) (pstext p "" 1)) (princ) ) ;; (pstext "Prefix Text" "Suffix Text" <mode>) ;; ;; <mode> = 0 - single selection ;; = 1 - window selection ;; ;; Author: Lee Mac 2011 - www.lee-mac.com (defun pstext ( preftext sufftext mode / a e i s ) (cond ( (= 0 mode) (while (progn (setvar 'ERRNO 0) (setq e (car (nentsel))) (cond ( (= 7 (getvar 'ERRNO)) (princ "\nMissed, try again.") ) ( (eq 'ENAME (type e)) (if (wcmatch (cdr (assoc 0 (entget e))) "TEXT,MTEXT,ATTRIB") (entmod (setq e (entget e) a (assoc 1 e) e (subst (cons 1 (strcat preftext (cdr a) sufftext)) a e) ) ) (princ "\nInvalid Object.") ) ) ) ) ) ) ( (setq s (ssget "_:L" (list '(0 . "TEXT,MTEXT")))) (repeat (setq i (sslength s)) (entmod (setq e (entget (ssname s (setq i (1- i)))) a (assoc 1 e) e (subst (cons 1 (strcat preftext (cdr a) sufftext)) a e) ) ) ) ) ) (princ) ) The command for the above is pretext. 1 Quote Link to comment Share on other sites More sharing options...
BIGAL Posted June 18, 2020 Share Posted June 18, 2020 Nice code Lee as usual maybe OP has limited lisp experience added a couple of extras. (defun c:pretext ( / p ) (if (/= "" (setq p (getstring t "\nSpecify prefix: "))) (pstext p "" 1)) (princ) ) (defun c:sufftext ( / s ) (if (/= "" (setq s (getstring t "\nSpecify suffix: "))) (pstext "" s 1)) (princ) ) (defun c:presuff( / p s) (if (and (/= "" (setq p (getstring t "\nSpecify prefix: "))) (/= "" (setq s (getstring t "\nSpecify suffix: "))) ) (pstext p s 1) ) (princ) ) 1 Quote Link to comment Share on other sites More sharing options...
lamensterms Posted January 23 Share Posted January 23 Just hopping in to say thanks to Lee and Bigal - very useful LISP as always Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 23 Share Posted January 23 7 hours ago, lamensterms said: Just hopping in to say thanks to Lee and Bigal - very useful LISP as always I'm pleased it's still proving useful after all these years! Quote Link to comment Share on other sites More sharing options...
3dwannab Posted June 9 Share Posted June 9 (edited) Anyone having an issue whereby you want to add a space to the suffix or prefix, like: prefix = "Bug with dynmode " suffix = " set it to 0 for the duraction of the program". This issue has been around for a long time. Here's that fix for anyone that may need it. (defun c:test1 (/ acDoc prefix suffix var_cmdecho var_dynprompt) (defun *error* (errmsg) (and acDoc (vla-EndUndoMark acDoc)) (and errmsg (not (wcmatch (strcase errmsg) "*CANCEL*,*EXIT*")) (princ (strcat "\n<< Error: " errmsg " >>\n")) ) (setvar 'cmdecho var_cmdecho) (setvar 'dynprompt var_dynprompt) ) ; Start the undo mark here (setq acDoc (vla-get-ActiveDocument (vlax-get-acad-object))) (or (vla-EndUndoMark acDoc) (vla-StartUndoMark acDoc)) ; Get any system variables here (setq var_cmdecho (getvar "cmdecho")) (setq var_dynprompt (getvar "dynprompt")) ; Set any system variables here (setvar 'cmdecho 0) (setvar 'dynprompt 0) ;; This needs to be set to 0 in order for whitespaces to be added after a prefix and before a suffix. (if (and (setq prefix (getstring T (strcat "\nSpecify prefix string: "))) (setq suffix (getstring T (strcat "\nSpecify suffix string: "))) ) (pstext prefix suffix 0) (princ "Suffix or prefix cancelled") ) (vla-EndUndoMark acDoc) (*error* nil) (princ) ) Edited June 9 by 3dwannab Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.