AutoCAD text find and replace as an API function?

AutoCAD text find and replace as an API function?

oransen
Collaborator Collaborator
1,531 Views
2 Replies
Message 1 of 3

AutoCAD text find and replace as an API function?

oransen
Collaborator
Collaborator

Does the AutoCAD API have a find and replace function, as found in AutoCAD itself?

0 Likes
Accepted solutions (2)
1,532 Views
2 Replies
Replies (2)
Message 2 of 3

john.uhden
Mentor
Mentor
Accepted solution

Apparently Express Tools provides an ACET-STR-FIND and an ACET-STR-M-FIND function.  I have never used either of them but you could experiment with them, OR wait for someone who knows to answer.

John F. Uhden

Message 3 of 3

CodeDing
Advisor
Advisor
Accepted solution

@oransen ,

 

The AutoLISP equivalent of this would be to use SSGET to capture all TEXT and/or MTEXT objects in the drawing, then (if you'd like) using one of the acet functions that @john.uhden is referring to. Something like:

...
(setq ssText (ssget "_X" '((0 . "*TEXT"))))
(setq txt2find "oldText")
(setq txt2replace "NEWTXT")
(setq isMtext nil)
(repeat (setq cnt (sslength ssText))
  (setq e (ssname ssText (setq cnt (1- cnt))))
  (setq eg (entget e))
  (if (member '(0 . "MTEXT") eg) (setq isMtext t))
  (if isMtext
    (setq txt (getpropertyvalue e "Contents"))
    (setq txt (getpropertyvalue e "TextString"))
  );if
  (setq txt (acet-str-replace txt2find txt2replace txt t))
  (if isMtext
    (setpropertyvalue e "Contents" txt)
    (setpropertyvalue e "TextString" txt)
  );if
);repeat
(prompt "\nText Replaced!")
...

...you can use the "(acet...)" function ONLY assuming you have express tools loaded.

 

Best,

~DD