Nate Holt's Blog

July 6, 2010

Generic text/mtext/attrib/attdef Find/Replace utility – AutoLISP

Filed under: Tips — nateholt @ 4:53 pm

Enter substrings for “find” and “replace”… then pick/pick/pick on TEXT, MTEXT, ATTRIB, ATTDEF text string values to update.

Frustration setting in as I worked on AutoCAD libraries for an electrical sub-station design application… copy circuit to a new drawing name, open, then use an attribute edit command to change a substring value in a dozen or so attributes. A little Find/Replace tool would be so welcome right now!

After 20 minutes of this tediousness, decided it was time to either find an existing tool or create a quick one. Found previous posting for a drawing-wide MTEXT find/replace utility. Good place to start.


Here is the result. Seems to work.

The flow is 1) enter “Find” substring, 2) enter “Replace” substring, 3) start picking on text. The text can be attributes, text entities, attribute definitions, and even multi-line text (multi-line attributes not covered in this version).

Here is an overview of how the original version was modified.

Step 1 – Renamed the source “.lsp” file to “text_fr.lsp”

Step 2 – Got rid of the drawing-wide “ssget” and changed to a loop of individual text picks (below).

Step 3 – added two blocks of code to deal with Attributes/Attribute definitions and with straight Text entities (below).

That should do it. It seems to work for me… speeded-up my effort to copy and modify my folder of sub-circuits. 

Here’s a simple example of it in operation. Starting out with a sample drawing that contains the substring “DN100” in three different places: an attribute that is part of a block insert instance, a single line of text, and a 3-line multi-line text entity just below it.

Let’s say we want to selectively change instances of “DN100” to now be “CM99”.

With the utility APPLOADED (download revised version  here – see update note below) we launch by typing TEXT_FR [Enter] at the “Command:” prompt.

To use… just APPLOAD the text_fr.lsp file. Then

1. Type TEXT_FR [Enter] at the AutoCAD command prompt

2. Enter the “Find” substring, Enter the “Replace” substring

3. Start picking on individual Text, MText, Attribute or Attribute Definition entities


There it is. Seemed to work really well for me!

UPDATE: user note below correctly points out that if this tool used to find/replace attribute values for AutoCAD Electrical “TAG1” attribute values, there is a good chance (especially if “IEC” tag mode is active) of confusion. This is because there is an Xdata tag name “VIA_WD_BASETAG” that is pushed out to parent components. This Xdata value carries the base copy of the overall component’s tag-ID. If the tag-ID is changed by our utility above, then this Xdata value needs to be processed as well. Here is a screenshot of the addition to our utility to deal with keeping this Xdata in synch. This code addition should lie dormant unless the tool is used on a “TAG*” attribute with AutoCAD Electrical in memory.

Update 2 – using the tool on ATTDEFs (as opposed to ATTRIBs) not working. Found that the utility was set to look at subrecord 1 instead of subrecord 2. Download revised version of tool here. I apologize for all the confusion this caused. – Nate.


  1. What about XDATA as in VIA_WD_BASETAG where the change of a TAG might cause problems with ACAD Electrical’s other functions.

    Comment by DSnodgrass — July 7, 2010 @ 5:25 pm

  2. Excellent point. Will update the utility to check for and update the special VIA_WD_BASETAG xdata flag if 1) user picks on an attribute, 2) the attribute tag name wildcard matches “TAG*”, 3) the VIA_WD_BASETAG xdata exists on the overall block insert instance, and 4) the Xdata value wild-card matches with the “Find” substring.


    Comment by nateholt — July 7, 2010 @ 11:47 pm

  3. […] QSELECT driving PROPERTIES command Generic Text/Mtext/Attdef/Attribute Find-Replace utility – AutoLISP […]

    Pingback by Index of AutoCAD Electrical Utilities – April 2006 through August 2010 « AutoCAD Electrical Etcetera — September 1, 2010 @ 3:50 pm

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at

%d bloggers like this: