Jump to content

How can I prefix text consistently??


coombsie11

Recommended Posts

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

Link to comment
Share on other sites

  • Replies 46
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    18

  • coombsie11

    10

  • jamesfear

    6

  • ML0940

    4

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?:ouch:

Link to comment
Share on other sites

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.... :wacko:

 

Try this, if it doesn't work, I am not sure what else to suggest.... maybe someone else will understand the problem better. :oops:

 

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

Link to comment
Share on other sites

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 :star:

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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. :D

 

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? :geek:

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...