• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    AutoCAD 2010/2011/2012 DWG Format

    Reply
    Contributor
    Posts: 19
    Registered: ‎03-27-2012
    Accepted Solution

    Replacing part of a text string

    1093 Views, 9 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?

    Please use plain text.
    Valued Mentor
    gjrcmb
    Posts: 321
    Registered: ‎06-21-2011

    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.

     


    Gavin Rouleau, PE
    C3D 2012 SP1, Win XP Home
    Please use plain text.
    *Expert Elite*
    3wood
    Posts: 613
    Registered: ‎03-25-2009

    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

    Please use plain text.
    Contributor
    Posts: 19
    Registered: ‎03-27-2012

    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

    Please use plain text.
    Valued Mentor
    gjrcmb
    Posts: 321
    Registered: ‎06-21-2011

    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.

    Gavin Rouleau, PE
    C3D 2012 SP1, Win XP Home
    Please use plain text.
    *Expert Elite*
    3wood
    Posts: 613
    Registered: ‎03-25-2009

    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

    Please use plain text.
    Contributor
    Posts: 19
    Registered: ‎03-27-2012

    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.

    Please use plain text.
    Contributor
    Posts: 19
    Registered: ‎03-27-2012

    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.

    Please use plain text.
    Valued Mentor
    gjrcmb
    Posts: 321
    Registered: ‎06-21-2011

    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

    Gavin Rouleau, PE
    C3D 2012 SP1, Win XP Home
    Please use plain text.
    Contributor
    Posts: 19
    Registered: ‎03-27-2012

    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.

    Please use plain text.