coombsie11 Posted September 17, 2008 Share Posted September 17, 2008 Hello all, I used to use an old LT command to prefix text consistently. This could be used for typing in floor level values, where the text would be constantly prefixed with FL_(and the typed text here) It was a repeater command and great for repetative repetative work. It was also very easy in LT to change the prefix to eg CH for ceiling heights etc.......... I believe that a block containing text was inserted each time and the prefix was acquired from here. Would be useful if there was one for suffixing text too. Please Help. Ta.. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 18, 2008 Share Posted September 18, 2008 I may not completely understand your problem but instead of inserting a block of the prefix text, could you not alter the existing text? Try this, let me know if it solves your problem (defun c:pretxt (/ pos txt ent en enlist txtval) (setvar "cmdecho" 0) (initget 1 "Prefix Suffix") (setq pos (getkword "\nSelect Position [Prefix/Suffix]")) (setq txt (getstring "\nType Prefix/Suffix: ")) (if (setq ent (entsel "\nSelect Text: " )) (progn (while (/= nil ent) (if (setq en (car ent)) (progn (setq enlist (entget en)) (setq txtval (cdr (assoc 1 enlist))) (cond ((= pos "Prefix") (setq txtval (strcat txt " " txtval)) ) ; end condition 1 (( = pos "Suffix") (setq txtval (strcat txtval " " txt)) ) ; end condition 2 ) ; end cond (setq enlist (subst (cons 1 txtval)(assoc 1 enlist)enlist)) (entmod enlist) (entupd en) ) ) (setq ent (entsel "\nSelect Text: ")) ) ; end while ) (alert "Please Select Text") ) (setvar "cmdecho" 1) (prompt "\nFunction Complete") (princ) ) Hope this Helps Quote Link to comment Share on other sites More sharing options...
ASMI Posted September 18, 2008 Share Posted September 18, 2008 Another: (defun c:ftxt(/ cMod cStr tSet) (vl-load-com) (initget 1 "Prefix Suffix") (setq cMod(getkword "\nAdd [Prefix/Suffix]: ")) (if(and (setq cStr(getstring T "\nSpecify string: ")) (setq tSet(ssget '((0 . "TEXT,MTEXT")))) ); and (foreach tx(mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr(ssnamex tSet)))) (if(= "Prefix" cMod) (vla-put-TextString tx (strcat cStr(vla-get-TextString Tx))) (vla-put-TextString tx (strcat(vla-get-TextString Tx)cStr)) ); end if ); end foreach ); end if (princ) ); end of c:ftxt Quote Link to comment Share on other sites More sharing options...
coombsie11 Posted September 18, 2008 Author Share Posted September 18, 2008 Thanks LeeMac, ASMI. Have tried both of these and they are grreat... but are not quite what I was after. Reading my initial thread again I probably didnt explain myself too well. What I need is not a command that pre/suffixes existing text. But one that will pre/suffix new text. eg On a floor plan dwg I will need to type a ceiling height with a prefix and a value - so each time I need to type eg CH 2.10, but with my old macro I would select the toolbar and type 2.10. There were others that were blocks of text eg Sill and Head heights for windows. I would type eg 0.85 2.16 and the result on screen would appear Sill 0.85 Head 2.16 Also all of this text would end up in a layer "TEXT", with bylayer color and the current layer that you were working in eg "WALL" would still remain current once the command was finished. Below is the old 2000LT macro for ceiling heights (CH) *^C^C-style;STANDARD;romans.shx;0.13;0.8;;N;N;N;-i;ch100;none;\;;;select;l;;x;l;setenv;CH;\_change;l;;;;;;CH $M=$(getenv,CH); And for Siil & Heads *^C^C-style;STANDARD;romans.shx;0.13;0.8;;N;N;N;-i;sill100;none;\;;;select;l;;x;l;setenv;Sill;\setenv;Head;\-ch;l;;;;;;SILL $M=$(getenv,Sill);-i;head100;none;@0,-0.205;;;;select;l;;x;l;-ch;l;;;;;;HEAD $(getenv,Head); Thanks for your help with this guys. Quote Link to comment Share on other sites More sharing options...
CAB Posted September 18, 2008 Share Posted September 18, 2008 As you may know the macro is just a simulation of the user entering the information at the command line. When you change ACAD versions some of the commands change there prompts or the order of the prompts which stop the macro from working. All you need to do is figure out what has changed in you new ACAD version and make the change in the macro. Break the macro apart by commands * this is repeat the command^C^C this is clear any command still active -style;STANDARD;romans.shx;0.13;0.8;;N;N;N; -i;ch100;none;\;;; insert the block, note that \ is "pause for user input" select;l;; select Last x;l; explode setenv;CH;\ _change;l;;;;;;CH $M=$(getenv,CH); Sorry but I have run out of time for this morning, off to an appointment. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 18, 2008 Share Posted September 18, 2008 Hi coombsie, After reading your reply, I modified my code slightly. Hopefully this is more appropriate (although, you may still want to go with the block insertion). (defun c:pretxt2 (/ currlay pos obj txtpos txt txtval) (setvar "cmdecho" 0) (setq currlay (getvar "clayer")) (initget 1 "Prefix Suffix") (setq pos (getkword "\nSelect Position [Prefix/Suffix]")) (initget 1 "CH FH") (setq obj (getkword "\nSelect Prefix or Suffix Text [CH/FH]: ")) (setq txtpos (getpoint "\nSelect Point for Text")) (while (/= nil txtpos) (setq txt (getstring "\nType Text: ")) (cond ((= pos "Prefix") (setq txtval (strcat obj " " txt)) ) ; end condition 1 (( = pos "Suffix") (setq txtval (strcat txt " " obj)) ) ; end condition 2 ) ; end cond (setvar "clayer" "TEXT") ; <--<< CHANGE THIS IF NECESSARY (command "-text" txtpos "2.5" ; <--<< CHANGE THIS IF NECESSARY "" txtval ) ; end text (setq txtpos (getpoint "\nSelect Point for Text")) ) ; end while (setvar "clayer" currlay) (setvar "cmdecho" 1) (prompt "\nFunction Complete") (princ) ) Quote Link to comment Share on other sites More sharing options...
borgunit Posted September 18, 2008 Share Posted September 18, 2008 Here is a little different slant on how to set the prefix. Set the USERS5 variable to whatever prefix you want and then just type in TXT whenever you want to create your special text... (defun C:TXT () (setvar "CMDECHO" 0) (command "_.text" (getpoint "\nWhere: ") "" "" (strcat (getvar "USERS5") (getstring "\nText: "))) (princ) ) Quote Link to comment Share on other sites More sharing options...
coombsie11 Posted September 18, 2008 Author Share Posted September 18, 2008 thanks borgunit, tried this out and replaced "USER5" with "CH", but came up with an error message. ; error: bad argument type: stringp nil Any suggestions? Quote Link to comment Share on other sites More sharing options...
borgunit Posted September 18, 2008 Share Posted September 18, 2008 Just checking, you set USERS5 and not USER5? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 19, 2008 Share Posted September 19, 2008 Another way of looking at it... I suppose you could use the code in two different ways: 1) have a code to encompass all prefixes/suffixes - i.e. the user enters the desired prefix/suffix. 2) have a different code assigned to each button and have a code for each prefix/suffix. 1) (defun c:userprefix (/ currlay pos obj txtpos txt txtval) (setvar "cmdecho" 0) (setq currlay (getvar "clayer")) (initget 1 "Prefix Suffix") (setq pos (getkword "\nSelect Position [Prefix/Suffix]")) (setq obj (getstring "\nType Prefix/Suffix Text: ")) (setq txtpos (getpoint "\nSelect Point for Text")) (while (/= nil txtpos) (setq txt (getstring "\nType Text: ")) (cond ((= pos "Prefix") (setq txtval (strcat obj " " txt)) ) ; end condition 1 (( = pos "Suffix") (setq txtval (strcat txt " " obj)) ) ; end condition 2 ) ; end cond (setvar "clayer" "TEXT") ; <--<< CHANGE THIS IF NECESSARY (command "-text" txtpos "2.5" ; <--<< CHANGE THIS IF NECESSARY "" txtval ) ; end text (setq txtpos (getpoint "\nSelect Point for Text")) ) ; end while (setvar "clayer" currlay) (setvar "cmdecho" 1) (prompt "\nFunction Complete") (princ) ) 2) (Prefix) (defun c:chprefix (/ currlay pos obj txtpos txt txtval) (setvar "cmdecho" 0) (setq currlay (getvar "clayer")) (setq obj "CH") ; <--<< CHANGE THE "CH" FOR A DIFFERENT PREFIX (setq txtpos (getpoint "\nSelect Point for Text")) (while (/= nil txtpos) (setq txt (getstring "\nType Text: ")) (setq txtval (strcat obj " " txt)) (setvar "clayer" "TEXT") ; <--<< CHANGE THIS IF NECESSARY (command "-text" txtpos "2.5" ; <--<< CHANGE THIS IF NECESSARY "" txtval ) ; end text (setq txtpos (getpoint "\nSelect Point for Text")) ) ; end while (setvar "clayer" currlay) (setvar "cmdecho" 1) (prompt "\nFunction Complete") (princ) ) 2) (Suffix) (defun c:chsuffix (/ currlay pos obj txtpos txt txtval) (setvar "cmdecho" 0) (setq currlay (getvar "clayer")) (setq obj "CH") ; <--<< CHANGE "CH" FOR A DIFFERENT SUFFIX (setq txtpos (getpoint "\nSelect Point for Text")) (while (/= nil txtpos) (setq txt (getstring "\nType Text: ")) (setq txtval (strcat txt " " obj)) (setvar "clayer" "TEXT") ; <--<< CHANGE THIS IF NECESSARY (command "-text" txtpos "2.5" ; <--<< CHANGE THIS IF NECESSARY "" txtval ) ; end text (setq txtpos (getpoint "\nSelect Point for Text")) ) ; end while (setvar "clayer" currlay) (setvar "cmdecho" 1) (prompt "\nFunction Complete") (princ) ) Let me know if this is what you were after. Hope this helps! Quote Link to comment Share on other sites More sharing options...
coombsie11 Posted September 20, 2008 Author Share Posted September 20, 2008 Yeh, sorry borgunit "USER5" was a typo. Have tried LeeMacs' prefix & suffix lsps, but get an error message. eg. If I type 2.10 after the "Type Text:" prompt - I get this error coming up. Unknown command "CH 2.20". Press F1 for help. Any ideas, I guess you have tested it yourself and it runs ok? I am running 2008 full version.. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 20, 2008 Share Posted September 20, 2008 Hi Coombsie, Yes, have tested the LISP on my machine (using ACAD 2004 full), and all work fine. So, it may be that the prompt order for the text function is slightly different for 2008. Also, I sometimes find that ACAD will occassionally "assume" a text height and/or rotation and skip to the "enter text" prompt - causing an error. Could you possibly post the prompts that appear when you type "-text" in the command bar? Quote Link to comment Share on other sites More sharing options...
coombsie11 Posted September 20, 2008 Author Share Posted September 20, 2008 Command: -text Current text style: "STANDARD" Text height: 0.1300 Annotative: No Specify start point of text or [Justify/Style]: Thanks for taking a look at this LeeMac Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 20, 2008 Share Posted September 20, 2008 After you have specified a start point, what are the following prompts? If its the same as ACAD 04, it should be: Start Point: Text Height: Text Rotation: Enter Text: Quote Link to comment Share on other sites More sharing options...
coombsie11 Posted September 20, 2008 Author Share Posted September 20, 2008 Sorry LeeMac, Just popped downstairs for a brew. It comes up with this Command: -TEXT Current text style: "STANDARD" Text height: 0.1300 Annotative: No Specify start point of text or [Justify/Style]: Specify rotation angle of text : Enter text: It looks like the text height element is omitted? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 20, 2008 Share Posted September 20, 2008 Yeah, because it doesnt ask for a text height, my LISP goes a bit wrong.... I am not sure why ACAD will sometimes prompt for a text height and at other times it will "assume" one. Or maybe its only on 2008 that it will not ask for one.... Try this, if it doesn't work, I am not sure what else to suggest.... maybe someone else will understand the problem better. (defun c:chprefix (/ currlay pos obj txtpos txt txtval) (setvar "cmdecho" 0) (setq currlay (getvar "clayer")) (setq obj "CH") (setq txtpos (getpoint "\nSelect Point for Text")) (while (/= nil txtpos) (setq txt (getstring "\nType Text: ")) (setq txtval (strcat obj " " txt)) (setvar "clayer" "TEXT") ; <--<< CHANGE THIS IF NECESSARY (command "-text" "J" "BL" txtpos "2.5" ; <--<< CHANGE THIS IF NECESSARY "" txtval ) ; end text (setq txtpos (getpoint "\nSelect Point for Text")) ) ; end while (setvar "clayer" currlay) (setvar "cmdecho" 1) (prompt "\nFunction Complete") (princ) ) Hope this helps Quote Link to comment Share on other sites More sharing options...
coombsie11 Posted September 20, 2008 Author Share Posted September 20, 2008 Tried again with fingers & toes crossed. still coming up with the same error message Type Text: 3.00 Unknown command "CH 3.00". Press F1 for help. No worries.. Thanks for all your help Lee Mac, your a Quote Link to comment Share on other sites More sharing options...
borgunit Posted September 20, 2008 Share Posted September 20, 2008 I tried the snippet I gave you in AutoCAD 2007 and had no issues. How are you loading the lsp? Save the snippet in a text file and save it as TXT.lsp Load it through the Load Application pulldown. Type in TXT and see what happens. It should prompt for an insertion point and then the text string. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 20, 2008 Share Posted September 20, 2008 Determined not to be defeated by this, I tried to go about it a different way - using the "entmake" function. But I must admit, this is the first time that I have used the "entmake" function, so could someone point out the mistake in this LISP.... please! (defun c:chprefix (/ currlay obj txtpos txt1 txtval ent1) (setvar "cmdecho" 0) (setq currlay (getvar "clayer")) (setq obj "CH") (setq txtpos (getpoint "\nSelect Point for Text")) (setq txt1 (getstring "\nType Text: ")) (setq txtval (strcat obj " " txt1)) (setq ent1 '( (0 . "TEXT") (8 . 1) (100 . "AcDbText") (10 0.0 0.0 0.0) (40 . 2.5) (1 . ".") (50 . 0.0) (41 . 1.0) (7 . "STANDARD") ) ) ; end setq (setq ent1 (subst (cons 10 txtpos) (assoc 8 ent1) ent1 ) ) ; end setq (entmod ent1) (setq ent1 (subst (cons 1 txtval) (assoc 1 ent1) ent1 ) ) ; end setq (entmod ent1) (entmake ent1) (setvar "clayer" currlay) (setvar "cmdecho" 1) (prompt "\nFunction Complete") (princ) ) Thanks! Quote Link to comment Share on other sites More sharing options...
coombsie11 Posted September 20, 2008 Author Share Posted September 20, 2008 Tried yours again borgunit. I have been saving the text as a lsp file and loading it as you stated. It seems to load just fine, but comes up with the same error message as before! When you said to change USERS5 to prefered prefix, did you mean... Changed yours from (defun C:TXT () (setvar "CMDECHO" 0) (command "_.text" (getpoint "\nWhere: ") "" "" (strcat (getvar "USERS5") (getstring "\nText: "))) (princ) ) To this (defun C:TXT () (setvar "CMDECHO" 0) (command "_.text" (getpoint "\nWhere: ") "" "" (strcat (getvar "CH") (getstring "\nText: "))) (princ) ) Where the USERS5 becomes CH as my required prefix. Or do you type SETVAR in cad and type USERS5 and change this to CH?? I may be making a mess of it. Am not familiar with lisp.. ................................................................... Lee Mac It works!!!! almost there. Prefixes the text with CH (Fantastic),but places it @ 0,0 and in the current working layer, rather tha layer "TEXT". Tried selecting a few differentlocations, but always ends up in the same place. What d ya think? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.