Find & replace script

Is there a script available–or can someone make one–that is similar to the TB_Add_Prefix_Or_Suffix script but with the option to find specific text and replace it with different text?

For example, if a have a character with all the layers named: James-
which I want to replace with: John-

Is this possible? I guess it would be called Find_And_Replace. This would make it easy to change or modify the layer names when necessary. Thanks!

It could definitly be done, but I doubt it has been done as there aren’t that many scripts out there.

It would be nice to have a collection of scripts that are available all in one place–probably on the Toon Boom Animate “How To” page. There are some scripts by Toon Boom that are included in the Sample Materials for the video tutorials and I’m sure others have made their own. If these were all in one place with a brief description of their function, that would be great!

For starters, perhaps the scripts which are in all the sample materials could be made available. I haven’t downloaded them all, but I know there are some there. That would be nice :slight_smile:

Maybe this is what you looking for, just past the code in the QSA Workbech select the node you want to replace the name in the Network view and call the script. It works also on multiple nodes at the same time. If you want sperate words use underscores or it will fail.

//SCRIPT START
function Find_And_Replace()
{
d = new Dialog;
d.title = “Find and Replace”;

var group = new GroupBox;

var findLE = new LineEdit;
var replaceLE = new LineEdit;
findLE.label = “Find:”;
replaceLE.label = “Replace:”;

group.add(findLE );
d.addSpace(1);
group.add( replaceLE);
d.add(group);

var rc = d.exec();

if (!rc)
{
return;
}

var _find = findLE.text;
var _replace = replaceLE.text;

var n = selection.numberOfNodesSelected();

for (i = 0; i < n; ++i)
{
var selNode = selection.selectedNode(i);
var nodeNamePath= selNode.split("/");
var nodeName = nodeNamePath[nodeNamePath.length - 1];

var newNodeName = nodeName.replace(_find, _replace);
var columnId = node.linkedColumn(selNode,“DRAWING.ELEMENT”);
var elementKey = column.getElementIdOfDrawing(columnId);
var newColumnName = newNodeName;

node.rename(selNode, newNodeName);
column.rename(columnId, newNodeName);
element.renameById( elementKey, newNodeName);

//System.println(newNodeName );
}
}
//SCRIPT END

2 Likes

Brilliant, Marcus! It worked like a charm! I knew there was some genius out there who could do this! Thanks so much!

Here’s a custom icon for it:

http://www.zebtoonz.com/images/find&replace.png

Edit: Marcus, I am remastering all the characters for my series and using your script. It is saving me a TON of time! Thanks again! This is a BIG help!

I’m glad I could help you and thanks for the icon, looks nice;)

We can think about creating a section on the website where we can house scripts, it may be something that we can put on the Tips and Tricks section. Or of course if anyone has written some useful scripts, then we could keep a section on the forums for users to post their own scripts.

I think it would indeed be possible for a find and replace script, but I’m not aware of one that exists already.

~Lilly

Hello everyone,

I’m trying to run the script for Harmony 21, but unfortunately there is a window alert that says: “Syntax is not valid: 5 : Illegal character”, whenever I try to verify the syntax in the Script Editor. Besides, line number 5 is highlighted: var group = new GroupBox;

Can anyone help me with this issue? It would be super useful

Thanks

Harmony 21 has its own find and replace script, you can find it and many more in Toolbars>Scripting under Windows menu.

TB_FindAndReplaceNodeName.js
Finds a given string and replaces it with another in all nodes, or selected nodes.