drewd1508 Posted June 7, 2007 Share Posted June 7, 2007 Hi There, Would like some help on a small problem that i have. I am trying to do a batch 'Find and Replace' exercise on a batch of autocad drgs. ie i need a program of some sort that will open a drawing, find a series of text strings and replace them with another series text strings and then save and close the drg. old text string could be say 537:00089 and new text string would be 537D:0032. There could be dozens/hundreds of numbers within a drg. Any ideas? Quote Link to comment Share on other sites More sharing options...
dbroada Posted June 7, 2007 Share Posted June 7, 2007 it would be a relatively simple task for either LISP or VBA. Are you saying you have a list of numbers to look for and whenever anyone of them is found it is replaced? Will at least one of the numbers appear in every drawing or will it not occur in othes? Will the number appear on their own or will they be part of a text string? Quote Link to comment Share on other sites More sharing options...
rkmcswain Posted June 7, 2007 Share Posted June 7, 2007 Hi There,Would like some help on a small problem that i have. I am trying to do a batch 'Find and Replace' exercise on a batch of autocad drgs. ie i need a program of some sort that will open a drawing, find a series of text strings and replace them with another series text strings and then save and close the drg. old text string could be say 537:00089 and new text string would be 537D:0032. There could be dozens/hundreds of numbers within a drg. Any ideas? ToolPac has a routine to do this. I have used it several times with success. Quote Link to comment Share on other sites More sharing options...
borgunit Posted June 7, 2007 Share Posted June 7, 2007 If you are using vb, then create a selection set of all text and/or mtext and then cycle through each one and then use the Replace method in vb. Quote Link to comment Share on other sites More sharing options...
drewd1508 Posted June 7, 2007 Author Share Posted June 7, 2007 Hi I need to make it clear that it is not the same text change in 100 different drgs. it is up to 100 text changes within a single drg, ie 100 different text strings each text string being a different no. (Autocad 2007) Cheers Quote Link to comment Share on other sites More sharing options...
borgunit Posted June 7, 2007 Share Posted June 7, 2007 It is possible. The code would just have to be written for your parameters. Still start with a selection of text, then cycle through and apply your test. What is it you want to change and how? (your if/then's) Quote Link to comment Share on other sites More sharing options...
drewd1508 Posted June 8, 2007 Author Share Posted June 8, 2007 I have series of schematic diagrams which have equipment shown on them ie valves/pumps etc. Next to each piece of equipment is a unique reference no eg '537:00989' inserted as dtext. This reference no has to be amended for each piece of equipment. I am trying to work out a quick way of identifying every ref no within a drg and then replacing each no with a new one. Quote Link to comment Share on other sites More sharing options...
dbroada Posted June 8, 2007 Share Posted June 8, 2007 are you asking for somebody to do it for you or are you looking for guidance on how to write a routine? Quote Link to comment Share on other sites More sharing options...
drewd1508 Posted June 8, 2007 Author Share Posted June 8, 2007 Im looking for guidance on how to write a routine as i have no autolisp/vba knowledge! Quote Link to comment Share on other sites More sharing options...
dbroada Posted June 8, 2007 Share Posted June 8, 2007 .. as i have no autolisp/vba knowledge!probably leaves me out as I don't have time to do a good job. Before you start coding write out what you need to do in psudo code. Something like... create a lookup table of search text/replace text get all text objects within drawing step through each piece of text if serch text is found, go to lookup table and replace when all text has been searched save drawing that can be expanded as you realise more steps are required both VBA and LISP are suitable for this sort of task but they can't (easilly) be mixed. Quote Link to comment Share on other sites More sharing options...
drewd1508 Posted June 8, 2007 Author Share Posted June 8, 2007 Cheers Dbroada, thanks for your help, the pseudo code you described is exactly the process we require. I think i have some people local to myself who are good at autolisp/vba. i will have a chat with them. Cheers Quote Link to comment Share on other sites More sharing options...
Terry Cadd Posted August 7, 2007 Share Posted August 7, 2007 Here is a function that I wrote to be used in programs, but it can be run on the command line using the following syntax: (FindReplaceAll "537:00089" "537D:0032") Use it with care, because it does exactly what it's named. Terry Cadd ;------------------------------------------------------------------------------- ; FindReplaceAll - Changes Text, Mtext, Dimensions and Attribute Block entities ; that have a Find$ string with a Replace$ string. ; Arguments: 2 ; Find$ = Phrase string to find ; Replace$ = Phrase to replace it with ; Syntax: (FindReplaceAll "old string" "new string") ; Returns: Updates Text, Mtext, Dimension and Attribute Block entities ;------------------------------------------------------------------------------- (defun FindReplaceAll (Find$ Replace$ / BlkEntList@ BlkEntName^ BlkEntType$ Cnt# DimEntList@ DimEntName^ DimEntType$ EntList@ EntName^ EntType$ FindReplace: Mid$ Mid2$ NewText$ Num# Replace$ SS& Text$) ;----------------------------------------------------------------------------- ; FindReplace: - Returns Str$ with Find$ changed to Replace$ ; Arguments: 3 ; Str$ = Text string ; Find$ = Phrase string to find ; Replace$ = Phrase to replace Find$ with ; Returns: Returns Str$ with Find$ changed to Replace$ ;----------------------------------------------------------------------------- (defun FindReplace: (Str$ Find$ Replace$ / Cnt# FindLen# Loop Mid$ NewStr$ ReplaceLen#) (setq Loop t Cnt# 1 NewStr$ Str$ FindLen# (strlen Find$) ReplaceLen# (strlen Replace$)) (while Loop (setq Mid$ (substr NewStr$ Cnt# FindLen#)) (if (= Mid$ Find$) (setq NewStr$ (strcat (substr NewStr$ 1 (1- Cnt#)) Replace$ (substr NewStr$ (+ Cnt# FindLen#))) Cnt# (+ Cnt# ReplaceLen#) );setq (setq Cnt# (1+ Cnt#)) );if (if (= Mid$ "") (setq Loop nil)) );while NewStr$ );defun FindReplace: ;----------------------------------------------------------------------------- ; Start of Main function ;----------------------------------------------------------------------------- (if (and (= (type Find$) 'STR)(= (type Replace$) 'STR)(/= Find$ "")) (progn (if (setq SS& (ssget "x" (list '(-4 . "<AND")'(-4 . "<OR")'(0 . "TEXT")'(0 . "MTEXT")'(0 . "DIMENSION")'(0 . "INSERT")'(-4 . "OR>")(cons 410 (getvar "CTAB"))'(-4 . "AND>")))) (progn (command "UNDO" "BEGIN") (setq Cnt# 0) (repeat (sslength SS&) (setq EntName^ (ssname SS& Cnt#) EntList@ (entget EntName^) EntType$ (cdr (assoc 0 EntList@)) Text$ (cdr (assoc 1 EntList@)) );setq (if (= EntType$ "INSERT") (if (assoc 66 EntList@) (progn (while (/= (cdr (assoc 0 EntList@)) "SEQEND") (setq EntList@ (entget EntName^)) (if (= (cdr (assoc 0 EntList@)) "ATTRIB") (progn (setq Text$ (cdr (assoc 1 EntList@))) (if (wcmatch Text$ (strcat "*" Find$ "*")) (progn (setq ReplaceWith$ (FindReplace: Text$ Find$ Replace$)) (entmod (subst (cons 1 ReplaceWith$) (assoc 1 EntList@) EntList@)) (entupd EntName^) );progn );if );progn );if (setq EntName^ (entnext EntName^)) );while );progn );if (if (wcmatch Text$ (strcat "*" Find$ "*")) (progn (setq ReplaceWith$ (FindReplace: Text$ Find$ Replace$)) (entmod (subst (cons 1 ReplaceWith$) (assoc 1 EntList@) EntList@)) (entupd EntName^) );progn );if );if (setq Cnt# (1+ Cnt#)) );repeat (command "UNDO" "END") );progn );if );progn );if (princ) );defun FindReplaceAll Quote Link to comment Share on other sites More sharing options...
drewd1508 Posted August 8, 2007 Author Share Posted August 8, 2007 Hi Terry, Thanks for your info, as i am not autolisp educated. How do i run this file. Do i have to copy the lisp file contents and save it somewhere in my c drive. I have tried the syntax but it does not recignize the commands on the command line. Cheers Drew Quote Link to comment Share on other sites More sharing options...
rkmcswain Posted August 8, 2007 Share Posted August 8, 2007 How do i run this file. Instructions here: http://www.cadtutor.net/forum/showthread.php?t=2791 Quote Link to comment Share on other sites More sharing options...
abzn Posted September 9, 2009 Share Posted September 9, 2009 Hi! Can somebody advice how to add multiline attributes to the processing by application (it is working only with single line attribute). Thank you Quote Link to comment Share on other sites More sharing options...
paulmcz Posted September 9, 2009 Share Posted September 9, 2009 Instructions here:http://www.cadtutor.net/forum/showthread.php?t=2791 Clicking on the link you posted produces this message: paulmcz, you do not have permission to access this page. This could be due to one of several reasons: 1. Your user account may not have sufficient privileges to access this page. Are you trying to edit someone else's post, access administrative features or some other privileged system? 2. If you are trying to post, the administrator may have disabled your account, or it may be awaiting activation. Why? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 9, 2009 Share Posted September 9, 2009 There is a better article here: http://www.cadtutor.net/forum/showthread.php?t=1390 Quote Link to comment Share on other sites More sharing options...
rkmcswain Posted September 9, 2009 Share Posted September 9, 2009 There is a better article here: http://www.cadtutor.net/forum/showthread.php?t=1390 The link I posted was good in 2007, it was replaced by the link Lee posted. They should have set up a forward on that old link.... Quote Link to comment Share on other sites More sharing options...
abzn Posted September 9, 2009 Share Posted September 9, 2009 Can somebody answer my question, please? Quote Link to comment Share on other sites More sharing options...
rkmcswain Posted September 10, 2009 Share Posted September 10, 2009 Can somebody answer my question, please? Is your original question related to the original topic in this thread? 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.