Jan 30, 2011

Nuke commandline render and python

Happy new year nukers, and non-nukers! First post this year, hopefully many more will follow it.
For the beginning, a little about commandline rendering with nuke, using pythonscript (got the idea from a mailing list post of mine). I mean with nuke you can't only execute a nuke file, but a pythonscript too. Like this:
nuke6.1.exe -x -F 1-30 myscript.py
One can think, that this is useful for creating nodes on the fly, like a read node, a write node, and execute that for converting sequences to another format. That is an option, but you also can open existing scripts and modify them. For this you can use the scriptOpen command. For example, if you have a nuke script called test_v001,nk, make a file called test.py, and write in it:

nuke.scriptOpen("e:\\Projects\\test_v001.nk")
(Replace the path with the path to your nuke file) After this in the .py file you can do modifications on your nukefile. Knob changes etc. And that's it. You can execute with the above mentioned cmdline command:
nuke6.1.exe -x -F 1-30 test.py

There is another option to do that. Slight change, but important, and you can do much more with it than rendering. You can not only execute, but literally open nuke files in command line (terminal) mode, hold it in memory, do changes (blindly) to that. For example I use that for my archiving script, open many nukefiles one by one, collect the used readnodes, and put those in a list etc. So I'm not executing the nukefile, just open it. But if I want I can render it too. I put a line more in the previous test.py file, so it will look like this:

nuke.scriptOpen("e:\\Projects\\test_v001.nk")
#do some modification on knobs if you need
nuke.execute('Write1', 1, 30, 1)


Here I called an execute command at the end of my pythonscript (I must know the name of my writenode)
I will use this script in my commandline command, that is almost the same as before:
nuke6.1.exe -t -F 1-30 test.py

But notice the -t flag! That means the test.py is not executed as a render, but treated as normal a pythonscript, just like if I put that in script editor in nuke. It will render the nukefile anyway, because the execute command in the test.py But as I said the great thing is to have an option to execute python scripts in terminal mode with the nuke interpreter.