Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

"Find & Replace" function

7 REPLIES 7
Reply
Message 1 of 8
Anonymous
481 Views, 7 Replies

"Find & Replace" function

I often use the "Find & Replace" function and everytime i have to fill in find word and replace word. if therer ten words need be replace and 20 more drawings have the same words, i have to spend a lot of time. I think there should be a table in which find words list in left side and replace words in right side, when i hit the RUN button, there words changed in second.

 

Thanks,

 

Peter

7 REPLIES 7
Message 2 of 8
Hallex
in reply to: Anonymous

Try this code it's not mine though

;;------------------------------------------------;;

(defun C:FRTT(/ elist filter found i matches matchlst newstr oldtext sset tf txt)

;; helpers
;; written by Tony Tanzillo © ;;
;; (string-subst )
;; 
;; Replaces first occurrance of with 
;; in 
;; 
;; Example:
;; 
;; (String-subst 
;; "Eleven" 
;; "Seven" 
;; "Four Score and Seven Years Ago"
;; )
;; 
;; Returns -> "Four Score and Eleven Years Ago"

(defun String-subst (new old str / i l)
(if (setq i (StrPos old str))
(strcat 
(substr str 1 (1- i))
new
(substr str (+ i (strlen old)))
)
str
)
)

(defun strpos (sub str / l wl i c)
(setq l (strlen str) 
wl (1+ (- l (strlen sub)))
i 0
c (substr sub 1 1)
)
(while (and (>= wl (setq i (1+ i)))
(or (/= (substr str i 1) c)
(not (strlcmp sub (substr str i))))
)
)
(if (>= wl i) i)
)

(defun Strlcmp (prefix string)
(eq prefix (substr string 1 (strlen prefix)))
)

;; Use VLISP if available:

;;;(if vl-string-subst 
;;;(setq string-subst vl-string-subst)
;;;)



;; you have to create list of pairs kind of  '(newstring . oldstring)
;; may write them as delimited text file usualy separated by semocolon before,
;; then read this file and build your match list, (here is just a dummy one for test):
  
(setq matchlst '(("newstring1" . "oldstring1")("newstring2" . "oldstring2");| ETC ...|;("newstringN" . "oldstringN")))
  
(setq filter (mapcar 'cdr matchlst))
(setq matches (mapcar 'car matchlst))
(setq tf "")
(foreach item filter
  (setq tf (strcat tf "*" item "*,")))

(setq filter (substr tf 1 (1-(strlen tf))))

(if (setq sset (ssget "_X" (list (cons 0 "*text")(cons 1 filter))));< -- select all texts and mtexts
  (progn
    (setq i 0)
  (repeat (sslength sset)
    (setq txt (ssname sset i)
	  elist (entget txt))
    (setq oldtext (cdr (assoc 1 elist)))
    (if (setq found  (car (vl-remove-if-not '(lambda (x)(vl-string-search x oldtext )) (mapcar 'cdr matchlst))))
      (progn
	(setq newstr (nth (vl-position found (mapcar 'cdr matchlst))matches))
	(setq elist (subst (cons 1 (string-subst newstr found  oldtext))(assoc 1 elist) elist))
	(entmod elist)))
    (setq i (1+ i)))
    )
  )

  (princ)
  )
(princ "\nStart command with FRTT ...")
(prin1)

;;----------------------------------------------------------------------;;

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 3 of 8
Anonymous
in reply to: Hallex

Thanks,

 

I can load it but for some reasons i cannot run it. Could you tell me how to run it?

Message 4 of 8
Hallex
in reply to: Anonymous

Click orange button at the very left bottom of this page

and copy code from there completely, then paste in

Notepad and save with .lsp extension, say "findrep_TT.lsp"

then just type FRTT in the command line after aploading the file

usual way from Tools->AutoLisp->Load application

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 5 of 8
Anonymous
in reply to: Hallex

i did the same way but it did not work. could you try it and send me lsp file?

 

thank you very much,

Message 6 of 8
Hallex
in reply to: Anonymous

wait 20 minutes or so please,

will be back soon

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 7 of 8
Hallex
in reply to: Anonymous

Try attached, tested om my A2010 with success

either with text and mtext

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 8 of 8
Anonymous
in reply to: Hallex

My screen is like below:

 

 

Command:

Command: APPLOAD FindReplace_TT.LSP successfully loaded.

Command: Start command with FRTT ...

Command:

Command: FRTT

Command:

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost