Automatic Write Node Versioning

Written by Peter Sauvey on .

if you run

nuke.root()['onScriptSave'].setValue("import re\n"+"\'[vV]\d+\',os.path.split(nuke.root().name())[1]).group()\n"+"for each in nuke.allNodes():\n"+" if each.Class() == \'Write\':\n" +" each[\'file\'].setValue(re.sub(\'[vV]\d+\',rootVersion,each[\'file\'].value()))")


your write nodes automatically increment their version number with the scripts version number when you save a new version of the script. 

So if you have a script called MyScript_v01.nk and a write node with a file path that ends with when you do File:Save New Version it will make all your write nodes with version numbers match the new name of the script. so MyScript_v02.nk and

The code goes into the onScriptSave box and when you save the script it uses re to split out the version number from the script name and applies it to all of the file knobs in all of the write nodes.


edit: made it a script command so it would be easier to apply.


+2 # Magno Borgo 2013-04-12 06:36
Another simpler possibility is to use TCL on the Write node, would give you the same result without too many code or python onScriptSave callbacks.

same as script file name:
[file rootname [file tail [value]]].yourextension

to get just the version:
assuming that you use "_" as a separator and that the version is the last thing on script name. (i.e anyfilename_v003.nk)
[lrange [split [file rootname [file tail [value]]] "_"] end end]

to get just the version:
assuming the version is on the last 4 characters of the script name (i.e anyfilename_v003.nk)
[join [lrange [split [file rootname [file tail [value]]] ""] end-3 end] ""]

When rendering several versions and being able to compare them later, one thing that I like is assigning a [date &#xHh;&#xMm;&#x Ss;] to the quicktime file name render. That way you end with several files, instead of overwriting the existing render.
-2 # Tor Andreassen 2014-08-12 22:52
very useful info.

Do you happen yo know what the TCL command would be if you wanted to keep everything before the version?
So including everything but the last 3 letters of the filename?
-1 # Tim BOWMAN 2014-11-07 18:14
One caveat when using TCL expressions in Write nodes;

If you use Nuke's background render, Nuke makes a copy of the script and renders from that. Your Write nodes will now name themselves according to the temp filename.

If you never use that functionality, TCL works great. If you do (or if your render manager makes copies of your scripts,) you might want to stick with a callback like this excellent example.
+1 # pedro lara 2016-06-22 18:52
Hi Magno.
In our studio we like to use subversions, such as _v03_002 or _v03_roto_001 to save several copies of the same script.

It should have to be be then the _$$$_ part ot the name that include a v at the begining, such as v03

Any way to code that?

+1 # Magno Borgo 2013-04-12 06:56
date tcl expression come out wrong above: &#x = %
+1 # Quico Noizeux 2013-05-14 09:41
I do it with tcl and regexp:

[regexp -inline -nocase {vd+} [file tail [value]]]
0 # Will Huelsemann 2013-12-25 00:52
thanks! very helpfull!
+3 # dean lewis 2015-02-08 16:35
I have tried running the above code in V9 and I get this:

expected an indented block (, line 5)
0 # 丁 峥 2015-07-01 09:13
+" each[\'file\'] replace +“ each[\'file\']
-1 # 丁 峥 2015-07-01 09:17
Double space after +"
-1 # Kristijan M 2016-01-05 12:31
Great tip! Maybe you could help me out on my specific write thingy.
I got a situation where I need to write mov from bunch of dpx...but I would like to take the name of the read file without numbering add _LUT to the name and write it out one folder above from where the dpx sequence is...everything happens in write node file out
for example I got:

And would like to write it like this:

Help please,
Thanks a bunch!
0 # Kristijan M 2016-01-05 13:27
Iwe come really close with this expression:
[join [lrange [file split [value [topnode].file] ] 0 end-2] /]/[basename [file rootname [value [topnode].file] ]]

I get path with one folder step above dpx files....get the file name without extension but leaves me the frame number...and thats not good...still not there...
+1 # Kristijan M 2016-01-05 18:09
Finally figured it out with a help from a friend!
This is my final expression, I used string range node to cut the last 4 digits...

[join [lrange [file split [value [topnode].file] ] 0 end-2] /]/[string range [basename [file rootname [value [topnode].file] ]] 0 end-4]
+1 # khush LP 2016-08-12 08:05
very helpful! but have run into another error.
Each new version(render) should go into its own new folder right? so the folder needs to be atuomatically created. how could i do this?

You have no rights to post comments

We have 164 guests and 5 members online