tca Posted September 15, 2014 Share Posted September 15, 2014 Does anybody have a script that would allow me to rename multiple symbols? I have some library folders where every symbol carries an old prefix that I would like to change at once. I've allready found some similar scripts for class renaming. thanks in advance. Tom Quote Link to comment
JBenghiat Posted September 15, 2014 Share Posted September 15, 2014 The following will change a substring in all symbols. Pass the handle to the first symbol in a folder to the FEO call to limit to a symbol folder. -Josh PROCEDURE MyScript; VAR newName :STRING; oldName :STRING; {---------------------------------------------------------------------} FUNCTION ChangeModelSym(h:HANDLE):BOOLEAN; VAR symName:STRING; labelH:HANDLE; labelN:DYNARRAY[] OF CHAR; BEGIN symName:=GetName(h); Message(Copy(symName, 1, 7)); IF Copy(symName, 1, Len(oldName))=oldName THEN BEGIN Delete(symName, 1, Len(oldName)); Insert(newName, symName, 1); Message(symName); SetName(h, symName); END; END; {---------------------------------------------------------------------} BEGIN oldName:='OldString'; newName:='NewString'; ForEachObjectInList(ChangeModelSym, 0, 2, FSymDef); END; Run(MyScript); Quote Link to comment
tca Posted September 16, 2014 Author Share Posted September 16, 2014 Hi Josh, Thanks for the answer. I'm new to scripting so can you lead me a little further? Where do I have to adapt the script to work with the following scenario? a symbolfolder called 'test' which has several symbols in it starting with '00' (00-symbolname). These would have to be changed to '01' (01-symbolname) Do I run this script directly from the resource browser? Quote Link to comment
JBenghiat Posted September 19, 2014 Share Posted September 19, 2014 Tom, You can either create a new script with in the Resource Browser and run from the script palette you are prompted to create (Window>[Doc Name]>Script Palettes), or run the script as a text file from the Tools > Plug-Ins menu. The ForEachObject call takes a handle (a unique ID tag assigned at script run) to the first symbol in a series. If you want the first symbol in a particular folder, replace FSymDef with FInFolder( GetObject( 'The_Folder' ) ) This will look for an object called "The_Folder" and return a handle to the first symbol inside it. Note this particular example is specifically for finding prefixes. If you want to change a suffix, you will need a couple more lines of code to find the start position of the substring. -Josh 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.