Andrew Neilson Posted April 2, 2010 Share Posted April 2, 2010 I'd like to rename a classes in a file to my own standard classes... A lot of surveys I receive contain the same class names and I want to turn each of those into names I prefer. Can anyone provide an example? Quote Link to comment
Miguel Barrera Posted April 2, 2010 Share Posted April 2, 2010 Here is an example; PROCEDURE RenameClassName; CONST kTOT_CLASS = 20; VAR i: INTEGER; curClass: STRING; oldList: ARRAY[1..kTOT_CLASS] OF STRING: newList: ARRAY[1..kTOT_CLASS] OF STRING: PROCEDURE ChangeName(objHdl: HANDLE); BEGIN SetClass(objHdl,newList); END; BEGIN oldList[1]:= 'old Name 1'; oldList[2]:= 'old Name 2'; ..... oldList[N]:= 'old Name N'; newList[1]:= 'new Name 1'; newList[2]:= 'new Name 2'; ..... newList[N]:= 'new Name N'; FOR i:= 1 TO kTOT_CLASS DO BEGIN curClass:= oldList; ForEachObject(ChangeName,((C=curClass))); END; END; Run(RenameClassName); I added an extra step there by assigning the name to curClass but I prefer this because ForEachObject can sometimes fail if the search string is not passed in simple terms. Quote Link to comment
Andrew Neilson Posted April 15, 2010 Author Share Posted April 15, 2010 Hi Miguel, This looks very promising but keeps returning the following error: Line #9: newList: ARRAY[1..kTOT_CLASS] OF STRING: | { Error: Expected ; } | { Error: Expected BEGIN } Thanks so much for the help! Quote Link to comment
MullinRJ Posted April 16, 2010 Share Posted April 16, 2010 oldList: ARRAY[1..kTOT_CLASS] OF STRING: newList: ARRAY[1..kTOT_CLASS] OF STRING: Hi Andrew, ???Both of these lines end in COLONS and should end in SEMICOLONS. They're typos. Change them as follows and you should be good. oldList: ARRAY[1..kTOT_CLASS] OF STRING; newList: ARRAY[1..kTOT_CLASS] OF STRING; ???The remaining errors are only due to the pseudo-code. Put in your specifics and it should compile. ???One thing to note when a compiler kicks an error, sometimes the error is on the immediately preceding line. If you can't find an error on the one reported, look at the previous one. Raymond Quote Link to comment
Andrew Neilson Posted April 27, 2010 Author Share Posted April 27, 2010 Thanks Miguel & Raymond, I've got the following working as an example, which changes objects classed as 'A' to 'Z'. Unfortunately its not working on objects in symbols. How might I modify this to include objects inside symbols? PROCEDURE RenameClassName; CONST kTOT_CLASS = 50; VAR i: INTEGER; curClass: STRING; oldList: ARRAY[1..kTOT_CLASS] OF STRING; newList: ARRAY[1..kTOT_CLASS] OF STRING; PROCEDURE ChangeName(objHdl: HANDLE); BEGIN SetClass(objHdl,newList); END; BEGIN oldList[1]:= 'A'; newList[1]:= 'Z'; FOR i:= 1 TO kTOT_CLASS DO BEGIN curClass:= oldList; ForEachObject(ChangeName,((C=curClass))); END; END; Run(RenameClassName); Quote Link to comment
MullinRJ Posted April 28, 2010 Share Posted April 28, 2010 Use ForEachObjectInList() and pass a handle to the first SymbolDef in the Symbol List. Add the following line and create a similar function that filters object by class so that you don't change everything. This is in addition to the code you already have. ForEachObjectInList(ChangeNameInSyms, 0, 2, FSymDef); { ALL objs, DEEP, SymDef List } HTH, Raymond Quote Link to comment
Miguel Barrera Posted April 28, 2010 Share Posted April 28, 2010 There are also keywords that can search in symbols, plugins, and viewports: INSYMBOL INOBJECT INVIEWPORT You would need to add any of these to the search criteria in your code such as: FOR i:= 1 TO kTOT_CLASS DO BEGIN curClass:= oldList; ForEachObject(ChangeName,(INSYMBOL & (C=curClass))); END; Quote Link to comment
Andrew Neilson Posted November 1, 2010 Author Share Posted November 1, 2010 Using the Script below to rename classes. Works great - but realized its changing the class setting to 'default' black pen, white fill, lineweight of 1 ect. What could I remove/add from the script so that renamed class retains the same settings as the old one? ~A PROCEDURE RenameClassName; CONST kTOT_CLASS = 300; VAR i: INTEGER; curClass: STRING; oldList: ARRAY[1..kTOT_CLASS] OF STRING; newList: ARRAY[1..kTOT_CLASS] OF STRING; PROCEDURE ChangeName(objHdl: HANDLE); BEGIN SetClass(objHdl,newList); END; BEGIN oldList[1]:= 'WDA-Ext Door-Color 1'; newList[1]:= 'WDA-Ext Door-01'; FOR i:= 1 TO kTOT_CLASS DO BEGIN curClass:= oldList; ForEachObject(ChangeName,(INSYMBOL & INOBJECT & INVIEWPORT & (C=curClass))); IF Len(curClass) > 0 THEN DelClass(curClass); END; END; Run(RenameClassName); Quote Link to comment
maarten. Posted November 2, 2010 Share Posted November 2, 2010 (edited) You can do that like this. Get the attribute of the old class and then set the attribute to the new class. You still need to ad all the other attributes that you want to keep to this exaple though, this example only sets the fore and background fill color. There's a list of Procedures in the FR under the "Classes" chapter. Most of them are about the attributes of the classes. {/// cut ///} curClass:= oldList[i]; IF Count(INSYMBOL & INOBJECT & INVIEWPORT & (C=curClass))<>0 THEN BEGIN GetClFillBack(curClass,red,green,blue); SetClFillBack(newList[i],red,green,blue); GetClFillFore(curClass,red,green,blue); SetClFillFore(newList[i],red,green,blue); {and so on} END; ForEachObject(ChangeName,(INSYMBOL & INOBJECT & INVIEWPORT & (C=curClass))); {/// cut ///} EDIT: or like Petri says, that would make it much easier and it will probable executes faster too. Edited November 2, 2010 by maarten. 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.