See the top rated post in this thread. Click here

Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 27

Thread: Find and Replace is NOT "Replacing" but adding to it??

  1. #11
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,714
    Login to Give a bone
    0

    Default Re: Find and Replace is NOT "Replacing" but adding to it??

    Quote Originally Posted by tedg View Post
    Yes you are mistaken, and you're forgiven

    I have a drawing (or two) that have section views, with elevation tags (in the form of blocks with attributes) which have different elevation values and some text.

    I want to "find" all the various elevations and replace them with SEE PLAN.

    I have done this before and it should work with an asterisk wild-card, I wasn't sure if there's a bug in 2013 as Cadtag mentioned.
    ....Ohhhhhhhhhh, I can haz understand now (it's been a particularly hard week here).

    I'll Post back as soon as work permits, but thanks for your patience while I catch up.

    Cheers
    Last edited by BlackBox; 2013-08-28 at 06:31 PM.
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  2. #12
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,714
    Login to Give a bone
    0

    Default Re: Find and Replace is NOT "Replacing" but adding to it??

    Could you post a sample drawing?
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  3. #13
    Certifiable AUGI Addict tedg's Avatar
    Join Date
    2005-06
    Location
    in the upper right corner
    Posts
    3,504
    Login to Give a bone
    0

    Default Re: Find and Replace is NOT "Replacing" but adding to it??

    Quote Originally Posted by BlackBox View Post
    Could you post a sample drawing?
    Sure, here's a dumbed down version, thanks.

  4. #14
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,714
    Login to Give a bone
    0

    Default Re: Find and Replace is NOT "Replacing" but adding to it??

    Sorry, I'm really short on time right now... So this brute-force sample will have to do for now (undo supported)... I'll come back to refine it later.

    HTH

    Code:
    (vl-load-com)
    
    (defun c:FIND+ (/ *error* _ReplaceString pattern newString acDoc oBlocks
                  objectName blockDef
                 )
    
      (defun *error* (msg)
        (if acDoc
          (vla-endundomark acDoc)
        )
        (cond ((not msg))                                                   ; Normal exit
              ((member msg '("Function cancelled" "quit / exit abort")))    ; <esc> or (quit)
              ((princ (strcat "\n** Error: " msg " ** ")))                  ; Fatal error, display it
        )
        (princ)
      )
    
      (defun _ReplaceString (obj)
        (if (wcmatch (vla-get-textstring obj) pattern)
          (vla-put-textstring obj newString)
        )
      )
    
      (if
        (and
          (setq pattern
                 (getstring T "\nEnter string pattern to search for: ")
          )
          (setq newString (getstring T "\nEnter new string: "))
        )
         (progn
           (vla-startundomark
             (setq acDoc (vla-get-activedocument (vlax-get-acad-object)))
           )
           (setq oBlocks (vla-get-blocks acDoc))
           (foreach y '(modelspace paperspace)
             (vlax-for x (vlax-get acDoc y)
               (cond
                 ((= "AcDbBlockReference"
                     (setq objectName (vla-get-objectname x))
                  )
                  (if (and (= "AcDbBlockReference" (vla-get-objectname x))
                           (= :vlax-true (vla-get-hasattributes x))
                           (setq blockDef (vla-item oBlocks
                                                    (vla-get-effectivename x)
                                          )
                           )
                      )
                    (foreach att (vlax-invoke x 'getattributes)
                      (vlax-for item blockDef
                        (if (= "AcDbAttributeDefinition"
                               (vla-get-objectname item)
                            )
                          (progn
                            (if (= (vla-get-tagstring att)
                                   (vla-get-tagstring item)
                                )
                              (_ReplaceString att)
                            )
                          )
                        )
                      )
                    )
                  )
                 )
                 ((wcmatch objectName "AcDbMText,AcDbText")
                  (_ReplaceString x)
                 )
               )
             )
           )
         )
      )
      (*error* nil)
    )
    ... Example from command line:

    Code:
    Command: find+
    
    Enter string pattern to search for: EL. *
    
    Enter new string: EL. SEE PLAN
    
    Command:
    Last edited by BlackBox; 2013-08-28 at 09:12 PM.
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  5. #15
    Member
    Join Date
    2015-11
    Posts
    22
    Login to Give a bone
    2

    Default Re: Find and Replace is NOT "Replacing" but adding to it??

    While BlackBox's code skills are impressive, for those that don't want to mess with a lisp routine and use the built-in find/replace...

    Thought I would post something mildly helpful for my first post...

    It is not a bug. The reason that the wild card isn't working, is that there is no "end" to the search string.
    For example, if you had a mtext paragraph (or line of text for that matter) that stated:

    "...blah, blah blah modEL. some more text etc, etc...."

    the EL. * replace would overwrite EVERYTHING after [modEL. ] even if what followed happened to be hundreds of characters long, and we don't want it to work like that (except in the OP's specific case for this specific drawing that doesn't have any other occurrence of "EL. ")

    To find/replace the elevation instead of adding to the string:
    Find: EL. *" <---(add the inch mark to give the wild card and "ending")
    Replace: EL. SEE PLAN
    (Found text = EL. 100'-0" , Modified text = EL. SEE PLAN)

    So to clarify; in the EL.[space][wildcard] search, the [wildcard] isn't really doing anything, but adding the inch mark - EL.[space][wildcard]["] - finds strings that adhere to EL. *[whatever is here]".

    Hope that makes sense..

  6. #16
    Certifiable AUGI Addict tedg's Avatar
    Join Date
    2005-06
    Location
    in the upper right corner
    Posts
    3,504
    Login to Give a bone
    0

    Default Re: Find and Replace is NOT "Replacing" but adding to it??

    Quote Originally Posted by reidcharley View Post
    While BlackBox's code skills are impressive, for those that don't want to mess with a lisp routine and use the built-in find/replace...

    Thought I would post something mildly helpful for my first post...

    It is not a bug. The reason that the wild card isn't working, is that there is no "end" to the search string.
    For example, if you had a mtext paragraph (or line of text for that matter) that stated:

    "...blah, blah blah modEL. some more text etc, etc...."

    the EL. * replace would overwrite EVERYTHING after [modEL. ] even if what followed happened to be hundreds of characters long, and we don't want it to work like that (except in the OP's specific case for this specific drawing that doesn't have any other occurrence of "EL. ")

    To find/replace the elevation instead of adding to the string:
    Find: EL. *" <---(add the inch mark to give the wild card and "ending")
    Replace: EL. SEE PLAN
    (Found text = EL. 100'-0" , Modified text = EL. SEE PLAN)

    So to clarify; in the EL.[space][wildcard] search, the [wildcard] isn't really doing anything, but adding the inch mark - EL.[space][wildcard]["] - finds strings that adhere to EL. *[whatever is here]".

    Hope that makes sense..
    First of all.... Welcome to AUGI and congrats on your first post!

    Second of all.. HOLY CR@P!, thanks!

    Is this a new thing?

    I have done this lots and lots of times before with a simple "*" wild-card and it has worked well, at least with lower versions of AutoCAD.

    According to 'HELP the asterisk is supposed to match any string, so it's assumed that (EL. *) would be selecting and replacing everything after EL.<space>.

    Is there anywhere this is documented so I/we can find out more?

    Thanks.

  7. #17
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,714
    Login to Give a bone
    0

    Default Re: Find and Replace is NOT "Replacing" but adding to it??

    Quote Originally Posted by reidcharley View Post
    While BlackBox's code skills are impressive, for those that don't want to mess with a lisp routine and use the built-in find/replace...
    That is kind of you to say, reidcharley... In deed, welcome to AUGI, and congrats on your first post!

    Quote Originally Posted by reidcharley View Post
    ...

    To find/replace the elevation instead of adding to the string:
    Find: EL. *" <---(add the inch mark to give the wild card and "ending")
    Replace: EL. SEE PLAN
    (Found text = EL. 100'-0" , Modified text = EL. SEE PLAN)
    Hoping that I had simply been overlooking the built-in functionality, I tried it (your suggestion of EL. *") on the sample drawing tedg uploaded here, and I was unsuccessful (see pics attached)... What version(s) are you using that this methodology is successful?

    Cheers
    Attached Images Attached Images
    Last edited by BlackBox; 2013-08-29 at 12:39 PM.
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  8. #18
    Certifiable AUGI Addict tedg's Avatar
    Join Date
    2005-06
    Location
    in the upper right corner
    Posts
    3,504
    Login to Give a bone
    0

    Default Re: Find and Replace is NOT "Replacing" but adding to it??

    Quote Originally Posted by BlackBox View Post
    That is kind of you to say, reidcharley... In deed, welcome to AUGI, and congrats on your first post!



    Hoping that I had simply been overlooking the built-in functionality, I tried it (your suggestion of EL. *") on the sample drawing tedg uploaded here, and I was unsuccessful (see pics attached)... What version(s) are you using that this methodology is successful?

    Cheers
    Hey BB,
    I tried it this morning and it worked for me, that's why I was so excited.
    I'm using AutoCAD 2013 (fwiw)

    I'll try it again on some other examples..

    *EDIT tried it on the sample drawing I posted yesterday, worked great for me (see screen shot).
    Last edited by tedg; 2013-08-29 at 01:47 PM. Reason: TESTED, ADDED SCREEN SHOT

  9. #19
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,714
    Login to Give a bone
    0

    Default Re: Find and Replace is NOT "Replacing" but adding to it??

    Quote Originally Posted by tedg View Post
    Hey BB,
    I tried it this morning and it worked for me, that's why I was so excited.
    I'm using AutoCAD 2013 (fwiw)
    No worries; it must have been an enhancement in 2013, as the screenshots I posted were from your sample drawing in 2012... Either way, I'm glad you got it sorted, and kudos to reidcharley.
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  10. #20
    Certified AUGI Addict cadtag's Avatar
    Join Date
    2000-12
    Location
    Cairo - no, not Illinois
    Posts
    5,069
    Login to Give a bone
    0

    Default Re: Find and Replace is NOT "Replacing" but adding to it??

    Quote Originally Posted by reidcharley View Post
    While BlackBox's code skills are impressive, for those that don't want to mess with a lisp routine and use the built-in find/replace...

    Thought I would post something mildly helpful for my first post...

    It is not a bug. The reason that the wild card isn't working, is that there is no "end" to the search string.
    For example, if you had a mtext paragraph (or line of text for that matter) that stated:

    "...blah, blah blah modEL. some more text etc, etc...."

    the EL. * replace would overwrite EVERYTHING after [modEL. ] even if what followed happened to be hundreds of characters long, and we don't want it to work like that (except in the OP's specific case for this specific drawing that doesn't have any other occurrence of "EL. ")

    To find/replace the elevation instead of adding to the string:
    Find: EL. *" <---(add the inch mark to give the wild card and "ending")
    Replace: EL. SEE PLAN
    (Found text = EL. 100'-0" , Modified text = EL. SEE PLAN)

    So to clarify; in the EL.[space][wildcard] search, the [wildcard] isn't really doing anything, but adding the inch mark - EL.[space][wildcard]["] - finds strings that adhere to EL. *[whatever is here]".

    Hope that makes sense..
    Thanks -- that makes sense.

    I'll cordially disagree though, with the statement that it's not a bug. It may be working as designed, but it's still a bug inasmuch as it does NOT work as expected, nor is it consistent with other uses of the '*' as a wildcard character that I've encountered in 30 years. Invariably the * has meant 'from here on to the end'. that end may be a 'end of line', end of string, or a predefined delimiter (eg the period in a dos filename).

    so: "the EL. * replace would overwrite EVERYTHING after [modEL. ] even if what followed happened to be hundreds of characters long, and we don't want it to work like that "

    is incorrect -- as I _do_ want and expect it to work like that. I can see advantages to having an ending character, but in the case of No Ending Character being supplied, the asterix should be a wcmatch the remainder of the string.

Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. AutoLisp to use "Find & replace"?
    By tmad101185 in forum AutoLISP
    Replies: 3
    Last Post: 2011-03-23, 12:36 PM
  2. Replies: 9
    Last Post: 2009-09-09, 07:43 AM
  3. Replacing "laymrg" in Acad2006 with own code
    By nojunk217 in forum AutoLISP
    Replies: 4
    Last Post: 2009-02-04, 07:55 PM
  4. Replies: 3
    Last Post: 2008-10-04, 12:15 PM
  5. Change Find and Replace "Zoom To" height
    By JeremiahM in forum AutoCAD General
    Replies: 2
    Last Post: 2007-06-04, 03:09 PM

Tags for this Thread

Posting Permissions

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