Replace all texts strings (in blocks also)

Replace all texts strings (in blocks also)

Anonymous
Not applicable
4,301 Views
20 Replies
Message 1 of 21

Replace all texts strings (in blocks also)

Anonymous
Not applicable

I wish to change a specific string of text in my drawings (one drawing at a time) with a substituted string of text.

I want this to act globally on all text in the drawing.

I have a short lisp routine (below) that works well on all text (single line and multiline) in the drawing.

However, it does not work on strings within blocks.

The strings in the blocks are single line and multiline text also (not attributes), yet they are not being found to change them also.

 

Can anyone provide help in adding to this routine so that it also works on text and multiline text inside blocks.

 

Below is the lisp I currently use. Note: the "TEXT TO BE FOUND" and the "TEXT TO BE REPLACED" are always static as we are actually just searching the drawing for all instances of a specific name and changing them to a different name.

 

Also, please know that this will be incorporated into a larger routine that will also change out logos and such; thus, I wish to use a quick lisp routine to doo all the functions.  Otherwise, yes I know, I'd use Find/Replace for this.

 

(vl-load-com)
(defun c:test1 (/ i obj RegExp ss)
   (if (setq ss (ssget "_X" '((0 . "MTEXT,TEXT"))))
      (progn
         (setq RegExp (vlax-get-or-create-object "VBScript.RegExp"))
         (vlax-put-property RegExp 'Global actrue)
         (vlax-put-property RegExp 'Ignorecase actrue)
         (vlax-put-property RegExp 'Multiline actrue)
         (vlax-put-property RegExp 'Pattern "TEXT TO BE FOUND")
         (repeat (setq i (sslength ss))
            (setq obj (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
            (if (vlax-write-enabled-p obj)
               (vla-put-textstring obj (vlax-invoke RegExp 'Replace (vla-get-textstring obj) "TEXT TO BE REPLACED"))
            )
         )
         (vlax-release-object RegExp)
      )
   )
   (princ)
)

 

 

Thanks for any help you can provide,

Barry Navarre

0 Likes
Accepted solutions (2)
4,302 Views
20 Replies
Replies (20)
Message 21 of 21

john.uhden
Mentor
Mentor
Thanks, Doug.

The Microsoft article fraggled my mind but I still don't get how it knows
(or tries to know) how to distinguish formatting codes within strings.
Maybe AutoCAD's mtext formatting syntax adheres to some Microsoft standard,
such as in MS Word? I have never dissected a Word document. It remains
magic to me.

John F. Uhden

0 Likes