replaceNodes v1.0


 
This location is for Registered Users Only.
Perhaps you need to login or register.
Contributor: Ivan Busquets
A function and a panel interface to replace nodes in a script.
Requirements:
6.0, 6.1 or later
Linux, Mac, Windows
20 Dec 2010
381

This is a convenience function and a Panel to replace all nodes of a certain class with new nodes of another class.

replaceNodesPanel_1

Features of this first release (v1.0):

  • User can choose to act on all nodes or selected nodes. If 'all nodes' is chosen, then you can also choose to act only at the root level or recursively go inside groups.
  • Panel allows to specify  more than 1 node class to be replaced. I.E. Replace all 'Grade', 'Add' and 'Multiply' nodes with 'ColorCorrect' nodes. To do so, just type the different node classes separated by a space.
  • Panel will only allow valid node classes. After typing in the text knob, it will compare what you typed with a list of available node classes. If no match is found, that particular node class gets deleted from the text knob. For convenience, the panel will also try to produce a case-insensitive match if it doesn't find an exact match. I.E. 'ColorCorrect', 'colorcorrect', 'colorCorrect', etc... should always turn into the right node class inside the text knob.
  • Panel gives a bit of info on how many nodes of the old class(es) were found, and in what context.
  • After choosing all the options, hitting Replace! will replace all the targeted nodes with a new node of the new class that was specified. If old and new nodes have a different number of maximum inputs (ie. replacing a Merge2 node with a Blur node), the behaviour should be the same as replacing those nodes in the interface using Ctrl + Shift + Drag new node on top of the old one. This ensures the mask input will always be connected to the correct input, and that the new node won't try to use more inputs than it's capable of.
  • Additionally, depending on the options chosen in the panel, every new node will try to copy knob values from the old node, and restore links on any other nodes that were referencing the old node, so that they now reference the new node. Check the tootips for those options (replace knobs, replace expressions and restore Links) to find more about them.
  • Apart from the Panel, the main function behind it, replaceNodes(), is exposed if someone wants to use it in other python scripts, or expand it to handle different scenarios.

Install instructions:

  • Download replaceNodes.py, and copy it anywhere in your PYTHON_PATH or nuke.pluginPath
  • To use any of the functions inside, just import it either in your menu.py or your init.py:
import replaceNodes
  • From here on, you should be able to use the functions inside. There's 3 of them:

replaceNodes.launchReplaceNodesModalPanel()
replaceNodes.getAllNodesOfClass(...)
replaceNodes.replaceNodes(...)

Use help(functionName) on any of them for more info.

  • To add the panel launcher to a menu item:
m = nuke.menu('Nuke')
replaceMenu = m.addMenu('ReplaceNodes')
replaceMenu.addCommand('Replace Nodes Panel', 'replaceNodes.launchReplaceNodesModalPanel()')

 

I haven't tested this too thoroughly, so any feedback is more than welcome. :)

 


Please login in order to download these files.

Comments   

 
0 # Nic v 2011-08-08 20:38
Hey I've tried this and it works well, thanks! Now is it possible to replace filepaths with this tool?
 
 
0 # Ivan Busquets 2011-08-08 22:21
Hi,
No, this one is for node replacements only.

For filepath replacements, have a look at Frank's search & replace panel:
http://www.nukepedia.com/python-scripts/ui/searchreplacepanel/

You can also have a look at nukescripts.sea rch_replace(), which is simple, but you can expand from there.
 
 
0 # Josh Robertson 2012-11-07 13:05
Hey I've been needing something like this just I want it to do the same switch every time without needing to have the UI pop up. an example would be I have a gizmo that I want to swap a hue correct with a grade within the gizmo when a PY-button is pressed in the gizmos properties. That isnt exactly what it would do but it is an example and a switch node wont work for what I need. any Idea how I could go about doing this?
 
 
0 # Tiago Cabrita 2016-06-20 22:32
Hey,

I have been in need of a tool like this but I have an issue when trying to use it. The comps I work on come from someone else and they use the RSMB which I don't have. I usually replace them one by one as I work but it would be really handy to just swap them all at the same time.

The problem is, when I use the tool on those nodes, it does not find them. Though they are in the comp. I guess it is because I do not have the plugin, so it does not associate it with any class.

Any way around this?

Thanks.
 

You have no rights to post comments

We have 3159 guests and 96 members online