PDA

View Full Version : Lisp to add a prefix or suffix to selected text



JB_In_FLA
27th Jul 2004, 02:55 pm
I am finding myself lost at my new job without a few lisp routines that really made my life easier. All the routines did was allow you to select text and type in a prefix to add to it and the other allowed you to type a suffix to add to it. Does anyone have anything similar that they wouldn't mind posting for me? Any help is appreciated.

David Bethel
27th Jul 2004, 04:21 pm
;| HTH -David|;




;================================================= ======================
; AddFix.Lsp Mar 14, 2000
; Add Either Suffix Or Prefix To Selected Strings
;================== Start Program ======================================
(princ "\nCopyright (C) 2000, Fabricated Designs, Inc.")
(princ "\nLoading AddFix v1.0 ")
(setq af_ nil lsp_file "AddFix")

;================== Macros =============================================
(defun PDot ()(princ "."))

(PDot);++++++++++++ Set Modes & Error ++++++++++++++++++++++++++++++++++
(defun af_smd ()
(SetUndo)
(setq olderr *error*
*error* (lambda (e)
(while (> (getvar "CMDACTIVE") 0)
(command))
(and (/= e "quit / exit abort")
(princ (strcat "\nError: *** " e " *** ")))
(and (= (logand (getvar "UNDOCTL") 8) 8)
(command "_.UNDO" "_END" "_.U"))
(af_rmd))
af_var '(("CMDECHO" . 0) ("MENUECHO" . 0)
("MENUCTL" . 0) ("MACROTRACE" . 0)
("OSMODE" . 0) ("SORTENTS" . 119)
("MODEMACRO" . ".")
("BLIPMODE" . 0) ("EXPERT" . 0)
("SNAPMODE" . 1)
("ORTHOMODE" . 1) ("GRIDMODE" . 0)
("ELEVATION" . 0) ("THICKNESS" . 0)
("FILEDIA" . 0) ("FILLMODE" . 0)
("SPLFRAME" . 0) ("UNITMODE" . 0)
("UCSICON" . 1)
("HIGHLIGHT" . 1) ("REGENMODE" . 1)
("COORDS" . 2) ("DRAGMODE" . 2)
("CECOLOR" . "BYLAYER")
("CELTYPE" . "BYLAYER")))
(foreach v af_var
(and (getvar (car v))
(setq af_rst (cons (cons (car v) (getvar (car v))) af_rst))
(setvar (car v) (cdr v))))
(princ (strcat (getvar "PLATFORM") " Release " (ver)
" - Add Text Prefix/Suffix ....\n"))
(princ))

(PDot);++++++++++++ Return Modes & Error +++++++++++++++++++++++++++++++
(defun af_rmd ()
(setq *error* olderr)
(foreach v af_rst (setvar (car v) (cdr v)))
(command "_.UNDO" "_END")
(prin1))

(PDot);++++++++++++ Set And Start An Undo Group ++++++++++++++++++++++++
(defun SetUndo ()
(and (zerop (getvar "UNDOCTL"))
(command "_.UNDO" "_ALL"))
(and (= (logand (getvar "UNDOCTL") 2) 2)
(command "_.UNDO" "_CONTROL" "_ALL"))
(and (= (logand (getvar "UNDOCTL") 8) 8)
(command "_.UNDO" "_END"))
(command "_.UNDO" "_GROUP"))

(PDot);************ Main Program ***************************************
(defun af_ (/ olderr af_var af_rst st ns ss i en ed tv)
(af_smd)

(initget 1 "Prefix Suffix")
(setq st (getkword "\nAdd Prefix/Suffix (P/S): "))

(setq ns (getstring t "\nNew String To Add: "))

(and (setq ss (ssget '((0 . "*TEXT"))))
(setq i (sslength ss))
(while (not (minusp (setq i (1- i))))
(setq en (ssname ss i)
ed (entget en)
tv (cdr (assoc 1 ed))
ed (subst
(cons 1 (if (= st "Suffix")
(strcat tv ns)
(strcat ns tv)))
(assoc 1 ed) ed))
(entmod ed)))

(af_rmd))

(PDot);************ Load Program ***************************************
(defun C:AddFix () (af_))
(if af_ (princ "\nAddFix Loaded\n"))
(prin1)
;|================== End Program =======================================

JB_In_FLA
27th Jul 2004, 06:59 pm
Exactly what the doctor ordered! Thank you.

- Joe

Adesu
20th Oct 2004, 08:09 am
Hi JB_In_FLA,you can try my code

; aft is stand for add front text
; Design by Ade Suharna <mteybid@yuasabattery.co.id>
; 11 August 2004
; program no. 67/09/2004
; edit by Ade Suharna 10 September 2004
; 06 October 2004
(defun c:aft (/ ent info1 opt ed)
(while
(setq ent (entget (car (entsel "\nCLICK TEXT FOR EDIT:")))
info1 (cdr (assoc 1 ent))
opt
(getstring T
(strcat "\nENTER NEW TEXT" "<" info1 ">" ":"))
ed (subst (cons 1 (strcat opt info1))(assoc 1 ent) ent))
(entmod ed)
)
(princ)
)

; ta is stand for text add
; Design by Ade Suharna <mteybid@yuasabattery.co.id>
; 10 September 2004
; program no. 65/09/2004
; edit by Ade Suharna 06/10/2004
(defun c:ta (/ ent info1 opt ed)
(while
(setq ent (entget (car (entsel "\nCLICK TEXT FOR EDIT:"))))
(setq info1 (cdr (assoc 1 ent)))
(setq opt (getstring (strcat "\nENTER NEW TEXT" "<" info1 ">" ": ")))
(setq ed (subst (cons 1 (strcat info1 " " opt))(assoc 1 ent) ent))
(entmod ed)
)
(princ)
)

cadmanrob
30th Apr 2009, 11:56 pm
This routine is great. Thanks!

Lee Mac
1st May 2009, 12:18 am
This may help you in other ways:

http://www.cadtutor.net/forum/showthread.php?t=35234

asos2000
26th Aug 2009, 01:31 pm
thanx alanjt
its great but not working with attribute

alanjt
26th Aug 2009, 01:36 pm
thanx alanjt
its great but not working with attribute
it's not supposed to. i had no interest in adding a prefix/suffix to attributes when i created it.

;;; Allows user to add a Prefix and/or Suffix to selected
;;; Text, Mtext and Multileaders.
are you saying you would want to add a prefix/suffix to all attributes in a selected block, or just selected attributes within a block? if i have time today, when i get to work, i'll add it as an option.

asos2000
26th Aug 2009, 01:56 pm
Yes I would want to add a prefix/suffix to all attributes in selected blocks.

Could be optional to deal with all attributes in selected blocks and selected attributes withen a block?

alanjt
26th Aug 2009, 02:03 pm
Yes I would want to add a prefix/suffix to all attributes in selected blocks.

Could be optional to deal with all attributes in selected blocks and selected attributes withen a block?
totally possible, i've got class in a few, but i'll look at it after i get to work.

the code is free to the world, you are more than welcome to attempt to edit it yourself, just make note of it in the preface.

funkkybebel
7th Oct 2009, 12:53 pm
So did you looked for attribute suffix and prefix ?
Thank you for your help.

alanjt
7th Oct 2009, 05:28 pm
So did you looked for attribute suffix and prefix ?
Thank you for your help.

I really haven't had the time. However, the code is there and you are more than welcome to give it a try.

Cad64
6th Jan 2011, 04:57 pm
here's what i do. i had to completely write a new one after switching to annotative text & beginning the use of mleaders.

This is an old thread, but thank you for this Alan. You just saved me from several hours of very tedious work. :thumbsup: