a very useful routine! thanks a lot Lee!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:
Open a new file in Notepad and copy the above code into the new file.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) )
Now, you can start creating your own commands to prefix/suffix your text; the pstext function takes the format:
Where:Code:(pstext <PrefixText> <SuffixText> <Mode>)
<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) )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.Code:(defun c:test3 ( ) (pstext "myprefix " "" 1) )
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.





Reply With Quote

Bookmarks