Automatic Write Node Versioning

Written by Peter Sauvey on .

if you run

nuke.root()['onScriptSave'].setValue("import re\n"+"rootVersion=re.search(\'[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 MyRenderFile_v01.mov 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 MyRenderFile_v02.mov

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.

Comments   

 
+6 # 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 root.name]]].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 root.name]]] "_"] 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 root.name]]] ""] 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.
 
 
+4 # 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?
 
 
0 # 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.
 
 
+3 # 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?

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

[regexp -inline -nocase {vd+} [file tail [value root.name]]]
 
 
+2 # Will Huelsemann 2013-12-25 00:52
thanks! very helpfull!
 
 
+10 # 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 +"
 
 
-6 # 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 put...so
for example I got:
X:/0100_Project/DR/SHOTS/EP1_FINAL_v01/EP1_Shot_Kick/render/EP1_Shot_Kick_comp_v03_####.dpx

And would like to write it like this:
X:/0100_Project/DR/SHOTS/EP1_FINAL_v01/EP1_Shot_Kick/EP1_Shot_Kick_comp_v03_LUT.mov

Help please,
Thanks a bunch!
K.
 
 
-6 # 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] ]]_LUT.mov

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...
 
 
+4 # 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]LUT.mov
 
 
+3 # 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?
 
 
-2 # ILJOO LIM 2018-07-12 21:35
[lindex [split [lindex [split [value root.name] /] end] .] 0]
when I use this code, is it possible to bring 'previous'version?
for example, 'IJ_COMP_TEST_v 16', can I get 'IJ_COMP_TEST_v15'?
Thank you!
 

You have no rights to post comments

We have 2707 guests and 48 members online