+ Reply to Thread
Page 2 of 2 FirstFirst 1 2
Results 11 to 13 of 13
  1. #11
    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,816

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by eric_monceaux View Post
    @Lee Mac - My apologies for misunderstanding, once you broke it down that PSTEST was a program in itself, it made sense, and is now working great.
    You're welcome.

    Quote Originally Posted by eric_monceaux View Post
    ...On a side note, what kind of changes would need to be made to PSTEST.lsp to REMOVE a prefix or suffix?
    A function could quite easily be constructed to use the wcmatch function to test for the presence of the prefix / suffix string in the selected text, then, if a match is found, shorten the string by the appropriate number of characters (length of prefix / suffix) using the substr function.
    Lee Mac Programming

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

    Just another Swamper

  2. #12
    Senior Member nod684's Avatar
    Computer Details
    nod684's Computer Details
    Operating System:
    Windows 7 Home
    Discipline
    Architectural
    Using
    AutoCAD 2010
    Join Date
    Jul 2012
    Location
    Singapore
    Posts
    232

    Default

    Quote Originally Posted by Lee Mac View Post
    An alternative approach...

    How about a function that allows you to create your own short & simple prefix/suffix programs?


    Say you need to repeatedly prefix many text object with the same thing and don't want to repeatedly specify the prefix to use, you can quickly write a custom command to prefix the text without a prompt for the prefix.

    Below is a generic function requiring optional prefix and suffix text and an integer mode to determine the method of selection:

    Code:
    ;; (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)
    )
    Open a new file in Notepad and copy the above code into the new file.

    Now, you can start creating your own commands to prefix/suffix your text; the pstext function takes the format:


    Code:
    (pstext <PrefixText> <SuffixText> <Mode>)
    Where:

    <PrefixText> = Text to be appended to the front of the selected text objects

    <SuffixText> = Text to be appended to the end of the selected text objects

    <Mode> = Integer determining how text objects are selected.

    <Mode> = 0 - single selection of objects

    <Mode> = 1 - window selection of objects

    Here are some example programs:


    Code:
    (defun c:test1 ( )
        (pstext "Prefix" "Suffix" 0)
    )
    Code:
    (defun c:test2 ( )
        (pstext "" " mysuffix" 1)
    )
    Code:
    (defun c:test3 ( )
        (pstext "myprefix " "" 1)
    )
    In your open notepad file, add a few new lines after the previously copied code above, then copy the above three commands to the notepad file.

    Save the notepad file as anything you like with a ".lsp" extension (ensure the filetype is set to 'All Files').

    Now Open AutoCAD and type appload at the command-line.

    Select your saved notepad .lsp file.

    Load the file.

    Type either 'test1', 'test2', or 'test3' to start any of the defined commands.
    a very useful routine! thanks a lot Lee!
    "Memories fade but the scars still linger...."

  3. #13
    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,816

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by nod684 View Post
    a very useful routine! thanks a lot Lee!
    You're very welcome nod, glad you can make use of it
    Lee Mac Programming

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

    Just another Swamper

Similar Threads

  1. Add Prefix or suffix to all layers in a drawing
    By gman in forum AutoLISP, Visual LISP & DCL
    Replies: 19
    Last Post: 10th Oct 2011, 12:26 pm
  2. Add Prefix/Suffix to Multiple Dimensions?
    By ILoveMadoka in forum AutoLISP, Visual LISP & DCL
    Replies: 13
    Last Post: 17th Aug 2011, 01:41 pm
  3. Adding Prefix or Suffix to block attribute
    By harilalmn in forum AutoLISP, Visual LISP & DCL
    Replies: 9
    Last Post: 28th Jul 2011, 02:20 pm
  4. Lisp to add a prefix or suffix to selected text
    By JB_In_FLA in forum AutoLISP, Visual LISP & DCL
    Replies: 12
    Last Post: 6th Jan 2011, 04:57 pm
  5. text suffix
    By ollie in forum AutoCAD General
    Replies: 10
    Last Post: 31st Jan 2008, 02:36 pm

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