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.