Results 1 to 8 of 8

Thread: Routine to replace text

  1. #1
    Active Member
    Join Date
    2005-01
    Posts
    78
    Login to Give a bone
    0

    Default Routine to replace text

    I thought I used to have a "find and replace text" command but I cant remember if this was an AutoCAD tool are somthing I had to add on. Im looking for something that will replace the [ALT-189] "½" symbol with the [%%208] "½" symbol that I use. I would like it to do the same for "¼" and "¾" symbols as well. I want to add this code to a routine that I use for converting other peoples drawings to my own format. Does anyone have anything like this that they can share?

    I'm a LIST noobie so take it easy on me. I find I am ok with changing them a bit and adding more of what is already in a lisp so if you only do the code for the one fraction, I can take it from there.

    Thanks in advance.

  2. #2
    I could stop if I wanted to scwegner's Avatar
    Join Date
    2004-12
    Location
    Minneapolis, MN
    Posts
    449
    Login to Give a bone
    0

    Default Re: Routine to replace text

    Quote Originally Posted by methost
    I thought I used to have a "find and replace text" command but I cant remember if this was an AutoCAD tool are somthing I had to add on. Im looking for something that will replace the [ALT-189] "½" symbol with the [%%208] "½" symbol that I use. I would like it to do the same for "¼" and "¾" symbols as well. I want to add this code to a routine that I use for converting other peoples drawings to my own format. Does anyone have anything like this that they can share?

    I'm a LIST noobie so take it easy on me. I find I am ok with changing them a bit and adding more of what is already in a lisp so if you only do the code for the one fraction, I can take it from there.

    Thanks in advance.

    The command is "find". It's also accessable as the last option in your "edit" pull-down menu and as an icon that looks like a magnifying glass with text between the print preview button and cut button on the standard toolbar. Not trying to be snide here, but in the future, search in AutoCAD's built in help feature before posting. You'll get your answer faster.
    Can you take it from there or would you like help putting it into a routine?

  3. #3
    Active Member
    Join Date
    2005-01
    Posts
    78
    Login to Give a bone
    0

    Default Re: Routine to replace text

    Yep, I did know about the find feature, but I recall using something that ran a bit quicker. If you have the time to help me out with the code, I would be grateful. I would love to automate the process that I use 20 times on nearly every drawing that I touch.

  4. #4
    I could stop if I wanted to scwegner's Avatar
    Join Date
    2004-12
    Location
    Minneapolis, MN
    Posts
    449
    Login to Give a bone
    0

    Default Re: Routine to replace text

    Quote Originally Posted by methost
    Yep, I did know about the find feature, but I recall using something that ran a bit quicker. If you have the time to help me out with the code, I would be grateful. I would love to automate the process that I use 20 times on nearly every drawing that I touch.
    Gotcha. Check out these threads:

    http://forums.augi.com/showthread.php?t=5580
    http://discussion.autodesk.com/threa...sageID=3977171
    http://discussion.autodesk.com/threa...sageID=4271621
    http://discussion.autodesk.com/threa...sageID=1118070

    If you're looking to learn how to write something like that, try starting with something like this:
    Code:
    (ssget "x" '((0 . "TEXT") (1 . "STRINGTOSEARCHFOR")))

  5. #5
    Active Member
    Join Date
    2005-01
    Posts
    78
    Login to Give a bone
    0

    Default Re: Routine to replace text

    Quote Originally Posted by scwegner

    If you're looking to learn how to write something like that, try starting with something like this:
    Code:
    (ssget "x" '((0 . "TEXT") (1 . "STRINGTOSEARCHFOR")))
    Can you explain what each part of that string does? I think I can take it from there.

  6. #6
    I could stop if I wanted to scwegner's Avatar
    Join Date
    2004-12
    Location
    Minneapolis, MN
    Posts
    449
    Login to Give a bone
    0

    Default Re: Routine to replace text

    Quote Originally Posted by methost
    Can you explain what each part of that string does? I think I can take it from there.
    Sure. For future reference though, there's a nicely detailed explanation with examples of all the LISP commands in the AutoCAD help files (AlispRef.pdf) and a good free basic tutorial on afralisp.com. I'm glad you're going to try it yourself -you'll learn much better that way, but you may also want to download the LISP files I linked and look through them to see the ways others have gone about it. I didn't look through them at all myself, but there are plenty of people out there who can write code better and more elegantly than I ever could..

    Code:
    (ssget "x" ;;;creates a selection set, x indicates it should use the entire database
      '(;;;begins the list of things to filter for
        (0 . "TEXT");;;include text objects
        (1 . "STRINGTOSEARCHFOR");;; include objects that have whatever you write here in them
      );;;closes filter list
    );;;closes ssget
    Note that the example I gave only filters for dtext. Presumeably, you will want to add mtext and dimension text as well. You can use the code snippet I gave you the other day to delete blank text as a template.

  7. #7
    Active Member
    Join Date
    2005-01
    Posts
    78
    Login to Give a bone
    0

    Default Re: Routine to replace text

    Quote Originally Posted by scwegner
    Code:
    (ssget "x" ;;;creates a selection set, x indicates it should use the entire database
      '(;;;begins the list of things to filter for
        (0 . "TEXT");;;include text objects
        (1 . "STRINGTOSEARCHFOR");;; include objects that have whatever you write here in them Is this there I would put "½"
      );;;closes filter list
    );;;closes ssget
    Note that the example I gave only filters for dtext. Presumeably, you will want to add mtext and dimension text as well. You can use the code snippet I gave you the other day to delete blank text as a template.
    And where in the string to I instrut it to use %%208 as a replacement for ½

  8. #8
    I could stop if I wanted to scwegner's Avatar
    Join Date
    2004-12
    Location
    Minneapolis, MN
    Posts
    449
    Login to Give a bone
    0

    Default Re: Routine to replace text

    Quote Originally Posted by methost
    And where in the string to I instrut it to use %%208 as a replacement for ½
    The bit I gave you only makes a selection set of text entities with "STRINGTOSEARCHFOR" in them. You would then have to use entmod to change it. For an example, you might want to look at:
    http://discussion.autodesk.com/threa...sageID=1233428

    It's only now occured to me that I'm not sure whether there's a way in vanilla LISP that will work with Alt-code symbols or not. Any gurus out there who'd care to contribute?

Similar Threads

  1. Text Replace using CSV
    By mrsusan in forum AutoLISP
    Replies: 6
    Last Post: 2012-02-16, 09:39 AM
  2. Replies: 1
    Last Post: 2009-08-18, 11:20 PM
  3. Replies: 4
    Last Post: 2008-12-03, 06:39 AM
  4. Text search and replace routine across multiple drawing files
    By David van Erk in forum AutoCAD Customization
    Replies: 1
    Last Post: 2006-05-19, 10:31 PM
  5. Find and Replace Text
    By mark_a in forum Revit Architecture - Wish List
    Replies: 4
    Last Post: 2004-06-01, 02:04 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •