Replace characters in a text block

Replace characters in a text block

Anonymous
Not applicable
767 Views
5 Replies
Message 1 of 6

Replace characters in a text block

Anonymous
Not applicable

I have a text block, block name is "TITLEBLOCKTEXT"

The attribute tag is "PNUM"

 

I want to replace all instances of the character "A" with "J"

 

Example = A001 changed to J001.

 

I found how to change text strings, but nothing related to text in a block.  Any help is much appreciated!!

0 Likes
Accepted solutions (1)
768 Views
5 Replies
Replies (5)
Message 2 of 6

Kent1Cooper
Consultant
Consultant

Will FIND do what you want?  It can change text content within Attributes.

Kent Cooper, AIA
0 Likes
Message 3 of 6

Moshe-A
Mentor
Mentor
Accepted solution

@Anonymous ,

 

check this one.

 

Moshe

 

 

(defun c:A2J (/ ss old new)
 (if (setq ss (ssget '((0 . "insert") (2 . "titleblocktext") (66 . 1))))
  (foreach ename (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
   (if (not
          (vl-catch-all-error-p
            (setq old (vl-catch-all-apply
                               'getpropertyvalue (list ename "pnum")))
          )
       )
    (if (or
          (setq new (vl-string-subst "J" "A" old))
          (setq new (vl-string-subst "j" "a" old))
        )
     (vl-catch-all-apply 'setpropertyvalue (list ename "pnum" new))
    ); if
   ); if
  ); foreach  
 )

 (princ) 
)  

 

0 Likes
Message 4 of 6

Anonymous
Not applicable

That is going to find all letter A and I only want to replace the character in one attribute (PNUM).  The block contains 20+ attributes, so selecting it returns all character A's.

0 Likes
Message 5 of 6

Anonymous
Not applicable

It works great except it is asking for me to select objects.  Can it select the block text automatically rather than having to select it manually?  

I have 200 drawings I need to change

0 Likes
Message 6 of 6

Anonymous
Not applicable

Changing the top line to..

 

(setq ss (ssget "x" '((0 . "insert") (66 . 1) (2 . "TITLEBLOCKTEXT"))))

 

Makes it work perfectly.

0 Likes