y49sides Posted January 11, 2008 Share Posted January 11, 2008 I looking for a way to automate the find and replace. I have a large amount of drawings with a specific text notation " D.F." needs to be changed to "DF". I want to automate it for my users by creating an lisp and an icon on a toolbar. I tried writing it in the macro on an toolbar icon but I do not know how to get it past the dialog box. Can anyone point me in the right direction or have a lisp that will do that? Thanks in advance Quote Link to comment Share on other sites More sharing options...
CarlB Posted January 11, 2008 Share Posted January 11, 2008 Did you look at the similar threads in this forum, as shown at the bottom of this page? This topic has come up a few times. Quote Link to comment Share on other sites More sharing options...
y49sides Posted January 11, 2008 Author Share Posted January 11, 2008 yes, that is why I decided to post this question. I was looking for something a bit more specific. Thanks Quote Link to comment Share on other sites More sharing options...
fixo Posted January 11, 2008 Share Posted January 11, 2008 Try this but very quick and dirty (defun C:RT (/ acapp acsp adoc adocs fn fold full_name_list) (or (vl-load-com)) (setq fn (getfiled "Select *ANY .DWG FILE* in a desired folder : " "" "dwg" 4 ) fold (vl-filename-directory fn) full_name_list (vl-directory-files fold "*.dwg" 1) full_name_list (mapcar (function (lambda (x) (strcat fold "\\" x) ) ) full_name_list ) ) (setq acapp (vlax-get-acad-object) adocs (vla-get-documents acapp) ) (foreach fl full_name_list (setq adoc (vla-open adocs fl :vlax-false)) (setq acsp (vla-get-modelspace adoc)) (vlax-for lt (vla-get-layouts adoc) (vlax-for obj (vla-get-block lt) (if (eq "AcDbText" (vla-get-objectname obj)) (if (eq "D.F." (vla-get-textstring obj)) (vla-put-textstring obj "DF") ) ) ) ) (vla-save adoc) (vla-close adoc) ) ) (princ "\n\t***\tStart command with RT\t***") (princ) ~'J'~ Quote Link to comment Share on other sites More sharing options...
y49sides Posted January 11, 2008 Author Share Posted January 11, 2008 Thank you very much. I got it all set up but it's not switching the text out. The "D.F." is in a string with other text. Could it be that this lisp will only look for a text string with only "D.F." in it? Quote Link to comment Share on other sites More sharing options...
CAB Posted January 12, 2008 Share Posted January 12, 2008 That's exactly why. Replace this: (if (eq "D.F." (vla-get-textstring obj)) (vla-put-textstring obj "DF") ) with this: (if (wcmatch (vla-get-textstring obj) "*D.F.*") (vla-put-textstring obj (vl-string-subst "DF" "D.F."(vla-get-textstring obj))) ) Quote Link to comment Share on other sites More sharing options...
y49sides Posted January 12, 2008 Author Share Posted January 12, 2008 Cab, Thank you very much for all the help. Can this code be written for just one drawing at a time. It seems this code asks me to pick a .dwg file but it goes through all .dwg in that specific folder. Thanks again. Quote Link to comment Share on other sites More sharing options...
CAB Posted January 12, 2008 Share Posted January 12, 2008 Sure, try this: ;; Code by Fatty Mod by CAB (defun C:RT (/ acapp acsp adoc adocs fn) (vl-load-com) (if (setq fn (getfiled "Select .DWG FILE to replace text : " "" "dwg" 4)) (progn (setq acapp (vlax-get-acad-object) adocs (vla-get-documents acapp) ) (setq adoc (vla-open adocs fn :vlax-false)) (setq acsp (vla-get-modelspace adoc)) (vlax-for lt (vla-get-layouts adoc) (vlax-for obj (vla-get-block lt) (if (eq "AcDbText" (vla-get-objectname obj)) (if (wcmatch (vla-get-textstring obj) "*D.F.*") (vla-put-textstring obj (vl-string-subst "DF" "D.F." (vla-get-textstring obj)) ) ) ) ) ) (vla-save adoc) (vla-close adoc) ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
y49sides Posted January 12, 2008 Author Share Posted January 12, 2008 Cab, Thanks, I'll try that tomorrow. This code looks like it's not for the .dwg that I will currently be in. it looks like the user will still have to manually pick a .dwg. I was looking for it to change the text in the drawing i was in. i'm sorry if I sound like a pest. I really do appreciate all of the above info. Thanks again Quote Link to comment Share on other sites More sharing options...
fixo Posted January 12, 2008 Share Posted January 12, 2008 Here is edited version, sorry for belating (defun C:RT (/ acapp acsp adoc adocs fn fold full_name_list st) ;; local defun ;; by Michael Puckett (defun Replace ( oldText newText text / i ) (if (/= oldText newText) (while (setq i (vl-string-search oldText text)) (setq text (vl-string-subst newText oldText text i ) ) ) ) text ) (or (vl-load-com)) (setq fn (getfiled "Select *ANY .DWG FILE* in a desired folder : " "" "dwg" 4 ) fold (vl-filename-directory fn) full_name_list (vl-directory-files fold "*.dwg" 1) full_name_list (mapcar (function (lambda (x) (strcat fold "\\" x) ) ) full_name_list ) ) (setq acapp (vlax-get-acad-object) adocs (vla-get-documents acapp) ) (foreach fl full_name_list (setq adoc (vla-open adocs fl :vlax-false)) (setq acsp (vla-get-modelSpace adoc)) (vlax-for lt (vla-get-layouts adoc) (vlax-for obj (vla-get-block lt) (if (eq "AcDbText" (vla-get-objectname obj)) (if (wcmatch (setq st (vla-get-textstring obj)) "*D.F.*") (vla-put-textstring obj (Replace "DF" "D.F." st)) ) ) ) ) (vla-save adoc) (vla-close adoc) ) ) (princ "\n\t***\tStart command with RT\t***") (princ) Quote Link to comment Share on other sites More sharing options...
fixo Posted January 12, 2008 Share Posted January 12, 2008 Sure, try this: ;; Code by Fatty Mod by CAB (defun C:RT (/ acapp acsp adoc adocs fn) (vl-load-com) (if (setq fn (getfiled "Select .DWG FILE to replace text : " "" "dwg" 4)) (progn (setq acapp (vlax-get-acad-object) adocs (vla-get-documents acapp) ) (setq adoc (vla-open adocs fn :vlax-false)) (setq acsp (vla-get-modelspace adoc)) (vlax-for lt (vla-get-layouts adoc) (vlax-for obj (vla-get-block lt) (if (eq "AcDbText" (vla-get-objectname obj)) (if (wcmatch (vla-get-textstring obj) "*D.F.*") (vla-put-textstring obj (vl-string-subst "DF" "D.F." (vla-get-textstring obj)) ) ) ) ) ) (vla-save adoc) (vla-close adoc) ) ) (princ) ) Alan, thanks again Regards, Oleg Quote Link to comment Share on other sites More sharing options...
CAB Posted January 12, 2008 Share Posted January 12, 2008 Your original post led us to believe you wanted to process many drawings. To replace Plain Text in the current drawing this is all you need: Note that it doesn't process Mtext or Attributes. For That you need this (defun C:RT (/ adoc Old$ New$) (vl-load-com) (setq Old$ "D.F." New$ "DF") (setq adoc (vla-get-activedocument (vlax-get-acad-object))) (vlax-for lt (vla-get-layouts adoc) (vlax-for obj (vla-get-block lt) (if (eq "AcDbText" (vla-get-objectname obj)) (while (vl-string-search Old$ (vla-get-textstring obj)) (vla-put-textstring obj (vl-string-subst New$ Old$ (vla-get-textstring obj))) ) ) ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
y49sides Posted January 14, 2008 Author Share Posted January 14, 2008 CAB, Thanks. The last one work perfectly. I appreciate al the help. Quote Link to comment Share on other sites More sharing options...
Galantic Posted January 28, 2008 Share Posted January 28, 2008 Hi! Thanks for that code, it's very useful. I have same problem but I need to replace more than just one word. Can you help me? Example: D.F. --> DF and MOI --> JOI -Galantic Quote Link to comment Share on other sites More sharing options...
CAB Posted January 29, 2008 Share Posted January 29, 2008 Try this, list consist of pairs, add as many as needed (defun C:RT (/ adoc List$) (vl-load-com) (setq $List '(("D.F." "DF") ("MOI" "JOI"))) ; (Old$ New$) (setq adoc (vla-get-activedocument (vlax-get-acad-object))) (vlax-for lt (vla-get-layouts adoc) (vlax-for obj (vla-get-block lt) (if (eq "AcDbText" (vla-get-objectname obj)) (mapcar '(lambda(x) (while (vl-string-search (car x) (vla-get-textstring obj)) (vla-put-textstring obj (vl-string-subst (cadr x) (car x) (vla-get-textstring obj))) ) ) $List) ) ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
dznytoy Posted January 9, 2012 Share Posted January 9, 2012 (edited) I am in need of something similar but I would like it to process multiple drawings at once like the original code you were presenting, but I need to to work on Mtext. I tried the one from the link you gave but it doesn't seem to want to run for me. All I really want to do is scan thru all the drawings in a folder and delete "alum." from all occurrences in mtext. Dznytoy Edited January 9, 2012 by dznytoy added Quote Link to comment Share on other sites More sharing options...
BlackBox Posted January 9, 2012 Share Posted January 9, 2012 Lee's Batch Find & Replace Text routine is one of my favorites. Quote Link to comment Share on other sites More sharing options...
Least Posted January 9, 2012 Share Posted January 9, 2012 Very nice CAB. Is it possible to modify it so that it replaces whole words only? for instance: CABLE TROUGH CPS = a text string in the drawing ("E " "Eaves") = find replace setting results = CABLEavesTROUGH CPS whereas I'd like this to be ignored. cheers P Quote Link to comment Share on other sites More sharing options...
BlackBox Posted January 9, 2012 Share Posted January 9, 2012 Lee's Batch Find & Replace Text routine is one of my favorites. *cough* Give this a try *cough* Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.