FIND AND REPLACE USING AUTOLISP

FIND AND REPLACE USING AUTOLISP

sHubamyadav016
Enthusiast Enthusiast
419 Views
4 Replies
Message 1 of 5

FIND AND REPLACE USING AUTOLISP

sHubamyadav016
Enthusiast
Enthusiast

I tried to do manually find and replace command it work perfectfully but how to do with autolisp like I have  a drawing I want like through code I can select a drawing and after selecting I can replce text with any other text how to do it

0 Likes
420 Views
4 Replies
Replies (4)
Message 2 of 5

Moshe-A
Mentor
Mentor

@sHubamyadav016  hi,

 

You are aiming very high 🤣, FIND is a very strong command with dialog interface that scans the database as a whole working on texts, mtexts, dimensions, leaders and block attributes. cloning such a command require a lot of coding but to give a tiny touch on what that involve, here is MFIND command to find & replace on selected texts objects.

 

(defun c:mfind (/ text_replace ; local function
		  FWhat RWith i ename ;| local variables |;)

 (defun text_replace (ent oldStr newStr / edata text)
  (setq edata (entget ent))
  (setq text (cdr (assoc '1 edata))) 

  ; loop to replace duplicate oldStr
  (while (vl-string-search oldStr text)
   (setq text (vl-string-subst newStr oldStr text))
  )

  ; update entity database
  (entmod (subst (cons '1 text) (assoc '1 edata) edata))
 ); text_replace


 ; here start c:mfind
 (if (and
       (/= (setq FWhat (getstring "\nFind what: ")) "")
       (/= (setq RWith (getstring "\nReplace width: ")) "")
       (setq ss (ssget '((0 . "text"))))
     )
  (progn 
   (setq i -1)
   (repeat (sslength ss)
    (setq i (1+ i))
    (setq ename (ssname ss i))

    (text_replace ename FWhat RWith)
   ); repeat
   
  ); progn	
 ); if

 (princ)
); c:mfind

enjoy

Moshe

 

  

0 Likes
Message 3 of 5

sHubamyadav016
Enthusiast
Enthusiast

If I will not aim high why will I  post on Autodesk Community 😀 I expect your level is too much high 😎

0 Likes
Message 4 of 5

cadffm
Consultant
Consultant

Hi,

 

more flexible, more to your needs and customable, than FIND

+ If you have lisp programming skills, it's easy to create the another way for start&run:

The very big main function is offered here: Click

Sebastian

0 Likes
Message 5 of 5

CGBenner
Community Manager
Community Manager

@sHubamyadav016 

Hi, Did the information provided answer your question? If so, please use Accept Solution so that others may find this in the future. Thank you very much!

Did you find a post helpful? Then feel free to give likes to these posts!
Did your question get successfully answered? Then just click on the 'Accept solution' button.  Thanks and Enjoy!


Chris Benner
Community Manager

0 Likes