Ohnoto Posted April 20, 2011 Posted April 20, 2011 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. Quote
Lee Mac Posted April 20, 2011 Posted April 20, 2011 http://www.cadtutor.net/forum/showthread.php?56993-Change-text-inside-blocks&p=386109&viewfull=1#post386109 Quote
alanjt Posted April 20, 2011 Posted April 20, 2011 http://www.cadtutor.net/forum/showthread.php?56993-Change-text-inside-blocks&p=386109&viewfull=1#post386109 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"))) Quote
Ohnoto Posted April 20, 2011 Author Posted April 20, 2011 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 Quote
alanjt Posted April 20, 2011 Posted April 20, 2011 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. Quote
Ohnoto Posted April 20, 2011 Author Posted April 20, 2011 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. Quote
BIGAL Posted April 21, 2011 Posted April 21, 2011 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. Quote
Recommended Posts
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.