JBender Posted June 27, 2008 Share Posted June 27, 2008 I was wondering if anyone knew of a script that could perform a text find and replace from one data set to another data set. For example I would like change: 0001->0002 0003->0004 0005->0006 etc. I have many drawings in a package and need to duplicate the package, the only difference being part of the wire numbers. If I had this tool it would save me many hours. I was hoping to use the "Find-Replace Text" vectorscript and edit it to do what I want only to find that it is locked by NNA. I asked if they could send it to me to get me started, but they arn't interested in helping me make this program work more efficiently for me. Anything to get me started would be appreciated. Quote Link to comment
JBender Posted July 8, 2008 Author Share Posted July 8, 2008 (edited) I've written a script to do this. For those out there that understand handle lists, I need some help. I am having a hard time traversing all text objects in a drawing (across all layers). It will traverse across only one layer without going to the next. Also, When I count selected text objects, it will count ones on an inactive layer that you wouldn't notice are selected. So neede a way to state "CurrentLayer" = TRUE but can't find it in the docs. Any help is appreciated! Code: Edit - For some reason it won't show tabs - sorry. ----------------------------------------------------------- PROCEDURE Batch_FindReplace; {$DEBUG} VAR i,j,k,n : INTEGER; Selections : DYNARRAY[] OF STRING; FindChar : DYNARRAY[] OF CHAR; FindLen : INTEGER; ReplaceChar : DYNARRAY[] OF CHAR; ReplaceLen : INTEGER; SampleChar : DYNARRAY[] OF CHAR; SampleLEN : INTEGER; Match : INTEGER; h : HANDLE; BEGIN n := Count((T=Text) & (SEL=TRUE)); i := 1; ALLOCATE Selections[1..n]; h := FSActLayer; WHILE (h <> NIL) DO BEGIN IF GetType(h) = 10 THEN BEGIN Selections := GetText(h); i := i+1; END; h := NextSObj(h); END; ALLOCATE SampleChar[0..0]; ALLOCATE FindChar[0..0]; ALLOCATE ReplaceChar[0..0]; h := FObject; WHILE (h <> NIL) DO BEGIN IF (GetType(h) = 10) THEN BEGIN SampleChar := GetText(h); SampleLen := Len(SampleChar); i := 1; WHILE (i < n) DO BEGIN FindChar := Selections; FindLen := Len(FindChar); ReplaceChar := Selections[i+1]; ReplaceLen := Len(ReplaceChar); IF (SampleLen >= FindLen) THEN WHILE (j < ((SampleLen - FindLen)+1)) DO BEGIN FOR k := 0 TO (FindLen -1) DO BEGIN IF (SampleChar[(j+k)] = FindChar[k]) THEN Match := Match+1; END; IF (Match = FindLen) THEN BEGIN FOR k := 0 TO (FindLen -1) DO BEGIN SampleChar[(j+k)] := ReplaceChar[k]; END; SetSelect(h); SetText(h, SampleChar); j := (j+FindLen-1); END; Match := 0; j := j+1; END; i := i+2; j := 0; END; END; h := NextObj(h); END; END; Run(Batch_FindReplace); Edited July 8, 2008 by Jhaceun Quote Link to comment
Miguel Barrera Posted July 8, 2008 Share Posted July 8, 2008 It should be easier to just use this call: PROCEDURE ForEachObjectInLayer(actionFunc :PROCEDURE; objOptions :INTEGER; travOptions :INTEGER; layerOptions :INTEGER); Description: Traverses through all objects according to specified search options and applies the specified action to each object. The 'actionFunc' procedure should return false to continue with next object, or return true to stop the traversal. Note that the description says "The actionFunc procedure should return false". It should be a boolean Function rather than a procedure. FUNCTION actionFunc(objhdl: HANDLE): BOOLEAN; Quote Link to comment
ionw Posted July 8, 2008 Share Posted July 8, 2008 (edited) Miguel, You beat me to it. Exactly what I was going to suggest. I guess I will follow up with the table for the different options for the tool Ion Edited July 8, 2008 by ionw Quote Link to comment
JBender Posted July 9, 2008 Author Share Posted July 9, 2008 Thanks guys. I did happen upon that call while I was working on it yesterday. Since I'm new at this I wasn't sure out to set up another procedure or Function (Don't know the difference either) inside my code. Will they each then have their own variable definitions? Is it then necessary to pass variables somehow from one to the other (like a handle). In any case I put the while loop I had inside another to go between each Layer. I would, however, like to use the ForEachObjectInLayer call because it would give me the ability to traverse groups which I can't do right now. All in all this has already been a handy tool and I was able to use it on a project. I'm still interested in making this tool better (and there is plenty more I could do). Thanks. Quote Link to comment
ionw Posted July 9, 2008 Share Posted July 9, 2008 The structure is something like this: Procedure SearchObject; VAR {variable declarations} Function Selection(h :Handle):BOOLEAN; BEGIN {What you want done} END; BEGIN ForEachObjectInLayer(Selection,1,0,1); END; END; RUN(SearchObject); I simply snipped the code away from one of my tools that uses this functionality. Quote Link to comment
J. Miller Posted July 13, 2008 Share Posted July 13, 2008 Just a quick code note. I do believe the "&" is a short cut "AND" operator. If the left side is true it will not check the right side. To check both side of the equation I think you need to use "AND" in place pf "&". Of course, I may be wrong. n := Count((T=Text) & (SEL=TRUE)); Jeff Miller Quote Link to comment
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.