+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 13
  1. #1
    JB_In_FLA
    Guest

    Default Lisp to add a prefix or suffix to selected text

    Registered forum members do not see this ad.

    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.

  2. #2
    Super Member David Bethel's Avatar
    Discipline
    Multi-disciplinary
    David Bethel's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Commercial Food Service
    Using
    AutoCAD pre 2000
    Join Date
    Dec 2003
    Location
    Newport News, Virginia
    Posts
    1,925

    Default

    ;| HTH -David|;


    Code:
    ;=======================================================================
    ;    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 =======================================
    R12 (Dos) - A2K

  3. #3
    JB_In_FLA
    Guest

    Default

    Exactly what the doctor ordered! Thank you.

    - Joe

  4. #4
    Senior Member Adesu's Avatar
    Using
    AutoCAD 2005
    Join Date
    Feb 2004
    Location
    Indonesia-Tangerang
    Posts
    158

    Default

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

  5. #5
    Junior Member
    Using
    AutoCAD 2010
    Join Date
    Apr 2009
    Posts
    17

    Default

    This routine is great. Thanks!

  6. #6
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,708

    Default

    This may help you in other ways:

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

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

  7. #7
    Super Member asos2000's Avatar
    Computer Details
    asos2000's Computer Details
    Operating System:
    WinXP
    Using
    AutoCAD 2007
    Join Date
    Sep 2007
    Location
    Cairo Egypt
    Posts
    573

    Default

    thanx alanjt
    its great but not working with attribute
    Sorry for my English.

  8. #8
    Luminous Being alanjt's Avatar
    Using
    Civil 3D 2011
    Join Date
    Apr 2008
    Posts
    5,988

    Default

    Quote Originally Posted by asos2000 View Post
    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.

  9. #9
    Super Member asos2000's Avatar
    Computer Details
    asos2000's Computer Details
    Operating System:
    WinXP
    Using
    AutoCAD 2007
    Join Date
    Sep 2007
    Location
    Cairo Egypt
    Posts
    573

    Default

    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?
    Sorry for my English.

  10. #10
    Luminous Being alanjt's Avatar
    Using
    Civil 3D 2011
    Join Date
    Apr 2008
    Posts
    5,988

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by asos2000 View Post
    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts