Jump to content

Recommended Posts

Posted

I have searched throughout the interwebs for a good LISP program. The best I found has been... http://www.cadtutor.net/forum/showthread.php?35933-The-Best-Text-Find-And-Replace-LISP-Ever..., however it doesn't not affect attributes or text within blocks.

 

I am wanting this up to adjust multiple texts at a time, using the commands within it:

 

(tfindfun "REPLACE" "REPLACED" 1)

(tfindfun "PLACE" "PLACED" 1)

(tfindfun "LEAVES" "LEFT" 1)

and so on...

 

But I can't do this since it doesn't work with attributes or blocks.

Posted

Slightly modified to handle multiple strings:

 

(defun ReplaceBlockText (stringlist / _StringSubst doc str)
 (vl-load-com)
 ;; © Lee Mac 2011

 (defun _StringSubst (new old str / i l)
   (setq i 0
         l (strlen new)
   )
   (while
     (and
       (< i (strlen str))
       (setq i (vl-string-search old str i))
       (setq str (vl-string-subst new old str i)
             i   (+ i l)
       )
     )
   )
   str
 )

 (vlax-for block (vla-get-blocks (setq doc (vla-get-activedocument (vlax-get-acad-object))))
   (if
     (and
       (eq :vlax-false (vla-get-isXref block))
       (eq :vlax-false (vla-get-isLayout block))
     )
      (vlax-for obj block
        (if (wcmatch (vla-get-objectname obj) "AcDb*Text")
          ;; AJT
          (progn
            (setq str (vla-get-TextString obj))
            (vla-put-TextString
              obj
              (foreach string stringlist (setq str (_StringSubst (car string) (cdr string) str)))
            )
          )
          ;; AJT
        )
      )
   )
 )
 (vla-regen doc acActiveViewport)
 (princ)
)

eg.

(ReplaceBlockText '(("NEW1" . "OLD1") ("NEW2" . "OLD2")))

Posted

Thanks for the reply guys. However, this isn't working quite right, possibly because the text within the block are done in attributes.

Call Out Box.dwg

Posted
Thanks for the reply guys. However, this isn't working quite right, possibly because the text within the block are done in attributes.

Oops, I didn't even look at what Lee had coded it for searching. You have to change it to search attributes:

 

(defun ReplaceBlockText (stringlist / _StringSubst doc str)
 (vl-load-com)
 ;; © Lee Mac 2011

 (defun _StringSubst (new old str / i l)
   (setq i 0
         l (strlen new)
   )
   (while
     (and
       (< i (strlen str))
       (setq i (vl-string-search old str i))
       (setq str (vl-string-subst new old str i)
             i   (+ i l)
       )
     )
   )
   str
 )

 (vlax-for block (vla-get-blocks (setq doc (vla-get-activedocument (vlax-get-acad-object))))
   (if
     (and
       (eq :vlax-false (vla-get-isXref block))
       (eq :vlax-false (vla-get-isLayout block))
     )
      (vlax-for obj block
        (if (wcmatch (vla-get-objectname obj) "AcDb*Text,AcDbAttribute")
          ;; AJT
          (progn
            (setq str (vla-get-TextString obj))
            (vla-put-TextString
              obj
              (foreach string stringlist (setq str (_StringSubst (car string) (cdr string) str)))
            )
          )
          ;; AJT
        )
      )
   )
 )
 (vla-regen doc acActiveViewport)
 (princ)
)

 

BTW, I cannot test this.

Posted

I see what you changed with the wcmatch, but it's still not working on attributes. It's fine on regular text inside or outside a block, just not attributes.

Posted

I am sure Lee will not mind but search posts for his global block editor lisp its here or on his own web site and does what you want.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...