Jump to content

Prefix-suffix on multiple text items


Nick-1971

Recommended Posts

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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)
)

  • Thanks 1
Link to comment
Share on other sites

  • 7 years later...

@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.

Link to comment
Share on other sites

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.

  • Thanks 1
Link to comment
Share on other sites

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)
)

 

  • Thanks 1
Link to comment
Share on other sites

  • 3 years later...
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!

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...