Preceding text with text | Automate Find & Replace

Preceding text with text | Automate Find & Replace

Anonymous
Not applicable
5,653 Views
19 Replies
Message 1 of 20

Preceding text with text | Automate Find & Replace

Anonymous
Not applicable

Software version: AutoCAD 2015

 

Problem description: 

 

My drawing contains large number of data outlets. Each outlet is numbered, it is a sequential numbering using 3 digits (001, 002, 003...558, 559, 560). Suddenly I received a request to prefix each of the 3 digit numbers with a floor number (L01-001, L01-002, L01-003...L01-558, L01-559, L01-560). 

 

 

Question: 

 

Is there an in-built function in AutoCAD's "Find & Replace" to handle large number of these "pre-ceedings"? I have about 12 floors with each of the floors containing over 500 outlets. 

 

Notes:

Finding each individual outlet and replacing it manually could take a very long time. (Find 001 and click replace with L01-001, then change find to 002 and click replace with L01-002...etc all the way to 560*12 = 6720 times...)

 

Question_1_AutoCAD_Forums.PNG

 

I believe there can a better way to handle this. Help me please AutoCAD community, you are my only hope!

 

Note for angry pros: I did search the forums, and I am searching the forums - posting here is just one of the things that I do - I understand this question may have been asked elsewhere (although may have been phrased differently so I missed it) in which case a link is all that's needed to help me out. 

0 Likes
Accepted solutions (1)
5,654 Views
19 Replies
Replies (19)
Message 2 of 20

Anonymous
Not applicable

I found this post: 

 

https://forums.autodesk.com/t5/autocad-2007-2008-2009/add-prefix-to-existing-text/td-p/2003026

 

It doesn't solve my problem, because it does not search through the text - it only allows me to select objects to prefix. 

 

 

But given my objects are MText - this only adds prefix to the beginning. Which is nice, however not sufficient. 

0 Likes
Message 3 of 20

vladimir_michl
Advisor
Advisor

Just search for the strings you wan to prefix - e.g. "002" and use "prefix-*" as the replacement string.

 

For complex replacements based on regular expressions you can use srxText - see:

http://www.cadforum.cz/cadforum_en/qaID.asp?tip=4136

 

Vladimir Michl, www.cadstudio.cz

 

Message 4 of 20

3wood
Advisor
Advisor

@Anonymous wrote:

Is there an in-built function in AutoCAD's "Find & Replace" to handle large number of these "pre-ceedings"? I have about 12 floors with each of the floors containing over 500 outlets. 


I think you need add-ons to complete the task. e.g. ALTEXT.

0 Likes
Message 5 of 20

RobDraw
Mentor
Mentor

Have you considered using a wild card and apply the find replace to a selection set?


Rob

Drafting is a breeze and Revit doesn't always work the way you think it should.
0 Likes
Message 6 of 20

RobDraw
Mentor
Mentor

podmak wrote:

Note for angry pros: I did search the forums, and I am searching the forums - posting here is just one of the things that I do - I understand this question may have been asked elsewhere (although may have been phrased differently so I missed it) in which case a link is all that's needed to help me out. 


Where did this even come from?


Rob

Drafting is a breeze and Revit doesn't always work the way you think it should.
0 Likes
Message 7 of 20

Kent1Cooper
Consultant
Consultant

Clarify something for me:

 

In your dialog box image, you're asking to replace "008" with "L01-008".  The text of the Mtext object it found shows "L1-007 008".  Is the end result intended to be "L1-007 L01-008"?  Should an automated routine also replace the "007" part of that same text content with "L01-007", since that's also a 3-digit series?  [That would result in "L1-L01-007 L01-008".]

 

If not, meaning you don't want to add "L01-" before every instance of three numerical digits in a row, wherever they occur in any string, would it always be the case that the ones you want to prefix that to are at the end of the content?  And would there never be any strings ending in 3 digits in a row that you would not want that added to?  Under those conditions, I can imagine a way to get a routine to do that.

Kent Cooper, AIA
0 Likes
Message 8 of 20

pendean
Community Legend
Community Legend
0 Likes
Message 9 of 20

Anonymous
Not applicable

stackoverflow forums - those guys ripped me to pieces for asking a noob question 🙂 So I remained damaged. 

Message 10 of 20

Anonymous
Not applicable

No, I pasted the image in as "in-progress". 

 

All mtext objects on the drawing look like this: 

 

multiline text, usually 2 lines, but some have 4. 

 Question_1_AutoCAD_Forums_01.PNG

 

So basically, after I find a solution, I will have a way to effectively turn the above numbers to: 

 

L1-491

L1-492

 

L1-493

L1-494

 

etc...

0 Likes
Message 11 of 20

RobDraw
Mentor
Mentor

It looks like those text entities might be easy to make a selection set of with QSELECT to isolate them from other texts. Find and replace might work with a string of three wildcards, if that is possible. 


Rob

Drafting is a breeze and Revit doesn't always work the way you think it should.
0 Likes
Message 12 of 20

Anonymous
Not applicable

Hi Vladimir, 

 

thanks for the input, unfortunately this is almost exactly what I am trying to avoid doing. I don't want to search for each individual outlet (001, 002 etc...) and click replace with. Because I have 12 floors with each floor containing over 500 outlets. That's a lot of clicking... 

 

Also the thing doesn't understand "*" (asterisk symbol) to be used as the searched string, effectively replacing my numbers to *; as per the following image, regardless of whether the "Use wildcards" checkbox is on or off. ...

Question_1_AutoCAD_Forums_02.PNG

 

So... that's not a very funny story... 😞 

 

Thanks for your input anyway. 

0 Likes
Message 13 of 20

Kent1Cooper
Consultant
Consultant

FIND doesn't seem to like wildcards, but QSELECT can use them:

 

TripleDigits.PNG

But that will only select them all for you.  To do the adding of the prefix to the numbers collectively, you would need something like an AutoLisp routine.  The finding part would use the same wildcard string [read about them in Help for (wcmatch)], like this:

 

(ssget "_X" '((1 . "*###*")))

 

That has the further advantage over QSELECT that it can find Mtext and Text all at once [and even Dimensions if such content is part of an override, not of the measured distance], whereas with QSELECT you would have to run it more than once and Append the results together.

 

Then it would be a matter of stepping through the objects it finds and adding the prefix before all the triple-digit portions.  No time to work that up now, but I may come back to it if you or someone else doesn't work it out first.

Kent Cooper, AIA
0 Likes
Message 14 of 20

Anonymous
Not applicable

Hi 3wood, 

 

thanks for your suggestion. 

 

It's a nice ad-don, but man, did you pack it with notification windows... there are so many 😄 

 

 

Regretfully, it doesn't work for multi line text - it only adds the pre-fix to the first 3-digit number and skips the second line.

 

I appreciate your input nonetheless. 

0 Likes
Message 15 of 20

vladimir_michl
Advisor
Advisor

You might be able to use the "Replace All" option (button).

 

But in any case the mentioned srxText could help for complex replacements. In your case you may want to use it as follows:

 

APPLOAD srxtext.vlx

SRXTEXT2

search using: Regular

search pattern: ([^\d]|\b)(\d{3})\b

replace pattern: L1-$2

All

All

Yes to all

 

Vladimir Michl, www.cadstudio.cz  www.cadforum.cz

 

 

0 Likes
Message 16 of 20

Anonymous
Not applicable
Accepted solution

Hi Vladimir, 

 

thanks for your help. I did end up using the srxText function that uses .csv files to find and replace. 

 

 

The .csv function of srxText is exactly what I dreamed about - I am so glad someone came up with that. 

 

 

For anyone else that comes across the same problem like I did - http://www.cadstudio.cz/en/download.asp?file=srxTEXT

 

 

If the link stops working search for utility called srxText. 

 

You can test it for free and if it does what you want it to - you can buy it. Worked like a charm for me. 

Message 17 of 20

Anonymous
Not applicable

Hello.  I have a similar problem.  I'm trying the srx app but I can't seem to figure out the right expression to get the replace command to work.  I click a sample text for the search pattern, then I followed the directions to determine my replacement pattern but I can't get it to work.  

 

I need to append a prefix of "EX. " to text objects that are 7 numbers long then an E at the end

"1234567E" - "EX. 1234567E"

the wild card schema in the srx app is very different than what I'm  used to dealing with and there are different instructions depending if you use srxtext or srxtext2.  It says srxtext2 uses vb script which is a module that no longer comes stalk in Civil3D.  So I guess I would have to use the other.  Although it gives no warning if I try using srxtext2 command.

 

Can anyone help?

0 Likes
Message 18 of 20

vladimir_michl
Advisor
Advisor

I understand that the regular expression may sound complicated. Try to use SRXTEXT2 as the VBscript syntax is easier (not complicated additionally by LISP exceptions). VBscript in this case has nothing to do with the VBA support in AutoCAD.

For your case, the SRXTEXT dialog should be as follows - the :  (\d{7}E) means "capture the original string containing exactly 7 digits and E"

 

SRXTEXT2
Search texts using [Regular expression/Exact string/Substring] <Substring>: r
Enter the searched pattern: (\d{7}E)
Enter the replace pattern ($1$2 for regex captures): Ex.$1
Search only in [Layer/All] <All>:
Search only [Selected/All] <All>:
Number of searched entities: 4
1234567E-->Ex.1234567E
Perform [Replace/Yes to all/Exit]? <Exit>: y

 

Vladimir Michl, www.cadstudio.cz  www.cadforum.cz

 

0 Likes
Message 19 of 20

Anonymous
Not applicable

Thank you! That worked perfectly.  I'll be sure to get familiar with the wildcard syntax of this app.  It has the potential to be a very powerful time saver.

 

Thanks again!

0 Likes
Message 20 of 20

Llawrence
Explorer
Explorer

Hi Gents,

I wonder if someone can help me with a solution please?

I have about 300 drawings that I need to add a change to. All of the pipelines are from Phase 1 and we are now doing Phase 2 with minimal changes to the system. This means that the numbering needs to change. It's not nice n easy like a prefix or suffix but the addition of the number 20 almost right in the middle of the pipeline number, ie. from 25-CW-1210-13724-CS1-NI-01 to 25-CW-1210-2013724-CS1-NI-01.

Does anyone know how I can search for theses pieces of text then add the 20 right in the middle there?

I'm not quite getting the hang of the srxtext command so would really appreciate a hand please.

Thanks,

Lynda

0 Likes