Results 1 to 4 of 4

Thread: Find Replace Text in Blocks

  1. #1
    Member
    Join Date
    2007-05
    Posts
    3
    Login to Give a bone
    0

    Default Find Replace Text in Blocks

    I was wondering if anyone had a routine to do a find replace on text (single line/mtext) nested inside of multiple different blocks in one drawing.

    Thanks

  2. #2
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Find Replace Text in Blocks

    It's possible to create one, but is a bit of an overkill if it's just for a handfull of blocks types. In which case it's easier just to edit the block.

  3. #3
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Find Replace Text in Blocks

    Just had a check, it seems to work fine:
    Code:
    (defun c:TxtSR (/ ss en ed blk n str1 str2)
      (prompt "Select entities to search through: ")
      (setq    ss (ssget)
        n  0
      ) ;_ end of setq
      (setq str1 (getstring t "Enter string to search for: "))
      (setq str2 (getstring t "Enter string to replace with: "))
    
      (defun ReplaceString (ed / str m)
        (setq str (cdr (assoc 1 ed))
          m   0
        ) ;_ end of setq
        (while (setq m (vl-string-search str1 str m))
          (setq str (vl-string-subst str2 str1 str m))
          (setq m (1+ m))
        ) ;_ end of while
        (setq ed (subst (vl-list* 1 str) (assoc 1 ed) ed))
        (entmod ed)
        (entupd (cdr (assoc -1 ed)))
        ed
      ) ;_ end of defun
    
      (while (< n (sslength ss))
        (setq en (ssname ss n)
          ed (entget en)
        ) ;_ end of setq
        (if    (assoc 1 ed)
          (setq ed (ReplaceString ed))
        ) ;_ end of if
        (if    (= "INSERT" (cdr (assoc 0 ed)))
          (progn
        ;; Search through block's entities
        (setq blk en
              en  (tblsearch "BLOCK" (cdr (assoc 2 ed)))
        ) ;_ end of setq
        (if en
          (setq en (cdr (assoc -2 en)))
        ) ;_ end of if
        (while (and en (setq ed (entget en)))
          (if (assoc 1 ed)
            (setq ed (ReplaceString ed))
          ) ;_ end of if
          (setq en (entnext en))
        ) ;_ end of while
    
        ;; Search through attributes following block
        (setq en (entnext blk))
        (while (and en (setq ed (entget en)))
          (if (= "ATTRIB" (cdr (assoc 0 ed)))
            (setq ed (ReplaceString ed))
          ) ;_ end of if
          (setq en (entnext en))
        ) ;_ end of while
    
        (entupd blk)
          ) ;_ end of progn
        ) ;_ end of if
        (setq n (1+ n))
      ) ;_ end of while
      (setq ss nil)
      (gc)
    ) ;_ end of defun
    This only uses the command line.

    Moderator Note:
    Removed Comments Per Forum Guidelines.
    Last edited by Opie; 2008-01-29 at 02:47 PM. Reason: See Moderator Note

  4. #4
    Member
    Join Date
    2007-05
    Posts
    3
    Login to Give a bone
    0

    Default Re: Find Replace Text in Blocks

    Thank you

    That works exactly the way I would like it too.

    Reason why I need it is for job specific changes to blocks that only happen one every ten jobs. And to explode/burst some of these blocks creates other problems.

    Thanks again.

Similar Threads

  1. Text find and replace
    By Wish List System in forum Inventor Wish List
    Replies: 0
    Last Post: 2012-11-13, 03:48 PM
  2. Text Find and Replace
    By madyb in forum Revit Structure - General
    Replies: 3
    Last Post: 2009-10-29, 07:40 PM
  3. Need help with: Find and replace text
    By drdesignz in forum AutoCAD General
    Replies: 1
    Last Post: 2009-10-19, 01:03 PM
  4. VBA to find and replace text
    By bschueller in forum VBA/COM Interop
    Replies: 13
    Last Post: 2006-11-29, 10:58 PM
  5. Find and Replace Text
    By ccowgill in forum AutoLISP
    Replies: 60
    Last Post: 2006-09-02, 08:12 PM

Posting Permissions

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