AutoCAD 2010/2011/2012

AutoCAD 2010/2011/2012

Reply
Contributor
nothin
Posts: 19
Registered: ‎03-27-2012
Message 1 of 13 (3,040 Views)
Accepted Solution

Replacing part of a text string

3040 Views, 12 Replies
03-27-2012 03:07 PM

I am trying to add text to a set of text strings in a drawing.

 

The tricky part is that not all of the text strings are the same.

 

For example, change part numbers

 

123, 125, 456, 892

 

to

 

123-70, 125-70, 456-70, 892-70

 

Is there a way to do this for all of the strings at once?

Yes, add the (vl-load-com) as the second line of the program.  Also the file does need to end in .lsp

Valued Mentor
gjrcmb
Posts: 326
Registered: ‎06-21-2011
Message 2 of 13 (3,026 Views)

Re: Replacing part of a text string

03-27-2012 04:45 PM in reply to: nothin

Not aware of a built-in way, but you could use a lisp application.

 

For several lisp examples that provide the sort of thing you are asking about, see following post:

 

Text prefix/suffix
http://forums.augi.com/showthread.php?t=6364

 

Did not try all programs, but the one posted by Peter Jamtgaard seems to work well.

 


*Expert Elite*
3wood
Posts: 1,147
Registered: ‎03-25-2009
Message 3 of 13 (3,013 Views)

Re: Replacing part of a text string

03-28-2012 04:21 AM in reply to: nothin

Please try ALTEXT.vlx

As for your example, select all texts, then in the "Change text content:" dialogue box, set "Modified", "String", Insert at "Middle", set the position as "3", New text as "-".

 

3wood

CAD KITS

Contributor
nothin
Posts: 19
Registered: ‎03-27-2012
Message 4 of 13 (3,000 Views)

Re: Replacing part of a text string

03-28-2012 03:37 PM in reply to: gjrcmb

Thanks! I will give this a try.

 

I do have another twist to this problem though.

 

Sometimes I need to change the last two numbers to something different. The last two numbers of each string are always the same but they may be the same as two other numbers in the string. This makes it hard to use wildcards.

 

The number of digits in the string is always the same.

 

For example:

Change

 

1234500, 1002500, 5689400

 

to

 

1234570, 1002570, 5689470

Valued Mentor
gjrcmb
Posts: 326
Registered: ‎06-21-2011
Message 5 of 13 (2,991 Views)

Re: Replacing part of a text string

03-28-2012 08:25 PM in reply to: nothin

Well once again, there may not be a built-in way of substituting the last two characters with something else, but it can be done with programming.

 

I attached a fairly simple lisp program I created to remove the specified number of characters off of the end of Text or MText entities.  So you could use the attached program to remove the specified number of characters and then use one of the prefix, suffix applications previously referenced to add new suffix characters to the end.  Yes, the programs could be combined but maybe this is an endeavor for you.  I suggest you test out these programs to make sure they are doing what you want them to do without any issues.

 

The attached program will only work with Text and MText, not Attribute Definitions or Text Entities that are embedded within a block.  That can also be done, but there is a bit more programming involved.  Not sure what was the significance of the file you attached, but perhaps that is what your next question was.

 

Anyway, hope that gets you there, or at least points you in the right direction.

*Expert Elite*
3wood
Posts: 1,147
Registered: ‎03-25-2009
Message 6 of 13 (2,977 Views)

Re: Replacing part of a text string

03-29-2012 03:55 AM in reply to: nothin

Again, ALTEXT.vlx can achive this quite easily.

 

Example 1, adding same number to selected texts:

Change

1234500, 1002500, 5689400

to

1234570, 1002570, 5689470

Just simply add "70" as "Increment"  to "Number"

 

Example 2, replace last two digits to a same number no matter what figures they were.

Change

1234510, 1002534, 5689498

to

1234570, 1002570, 5689470

Step 1

Add a speciall character such as "-" to the third place counting from left.

The result will be:

12345-10, 10025-34, 56894-98

Step 2

Replace mode as "New", Change to "Number", Search from "Right", New text as "70", don't select "Dash as negtive symbol"

The result will be:

12345-70, 10025-70, 56894-70

Step 3

Use AutoCAD command FIND to replace text "-" with nothing.

The result will be:

1234570, 1002570, 5689470

 

3wood

CAD KITS

Contributor
nothin
Posts: 19
Registered: ‎03-27-2012
Message 7 of 13 (2,955 Views)

Re: Replacing part of a text string

03-29-2012 11:03 PM in reply to: gjrcmb

Thanks! I tried both the RemChar.lsp file and the textps.lsp from Jamtgaard that you suggested earlier.

 

They both worked great. But there was one quirk in the textps.lsp file.

 

I was able to start it up in the command window in ACAD but it would never actually change the text. Until I used the RemChar.lsp file. That one worked fine. Then I was able to use the textps.lsp file.

 

I'm not sure why this is. I have compared both programs. All I can think of is that the textps.lsp file is missing the text (vl-load-com). What can I say. I'm a newbie to this stuff.

 

Any ideas of what is wrong? Sorry I tried to attach the file but for some reason could not.

Contributor
nothin
Posts: 19
Registered: ‎03-27-2012
Message 8 of 13 (2,953 Views)

Re: Replacing part of a text string

03-29-2012 11:05 PM in reply to: gjrcmb

Nevermind. I guess I was able to attach a .txt version of the file textps.lsp. The version I used was a .lsp version.

Valued Mentor
gjrcmb
Posts: 326
Registered: ‎06-21-2011
Message 9 of 13 (2,945 Views)

Re: Replacing part of a text string

03-30-2012 06:22 AM in reply to: nothin

Yes, add the (vl-load-com) as the second line of the program.  Also the file does need to end in .lsp

Contributor
nothin
Posts: 19
Registered: ‎03-27-2012
Message 10 of 13 (2,910 Views)

Re: Replacing part of a text string

04-03-2012 08:13 AM in reply to: gjrcmb

I added the (vl-load-com) and it worked great! thanks.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.