PDA

View Full Version : Launch command-line renders from the Nuke UI.



tim.bowman
October 16th, 2008, 11:50 AM
I hacked up this script because I was frustrated with rendering in the Nuke UI, tired of typing out command-line render commands, and our renderfarm wasn't alive yet. I'm posting it because I bet there's other people in the same situation and I hope it can ease your pain.

This script launches a number of command-line render instances in the background and captures their output in log files which are saved to the same directory as the Nuke script. You are now free to keep working in the UI and have your renders happen in the background.

It works in Nuke5.0v2 on OS X. Maybe it works on other versions and platforms. If so, I'd love to hear about it.




#
# launchNukes_inNuke.py
#
# v01
#
# a script for launching single-core command-line nuke renderers
# from inside the Nuke UI.
#
# also saves log files of each instance's output to the same folder
# where the Nuke script lives.
#

import re
import nuke
import os
import sys

def launch_nukes():
a = nuke.knob("first_frame")
b = nuke.knob("last_frame")
start = int(a)
end = int(b)
incr = 1
instances = 1
_range = a+","+b
p = nuke.Panel("Launch Nukes")
p.addSingleLineInput("Frames to execute:", _range)
p.addSingleLineInput("Number of background procs:", instances)
p.addButton("Cancel")
p.addButton("OK")
result = p.show()

r = p.value("Frames to execute:")
s = p.value("Number of background procs:")
if r is None:
return
if s is None:
return
# this is the requested frame range
frames = r
# this is the number of instances to launch
inst = int(s)

(scriptpath, scriptname) = os.path.split(nuke.value("root.name"))
flags = "-ixfm 1"

print ">>> launching %s nuke instances" % inst

# create a frame range string for each renderer
for i in range(inst):
print ">>> generating range for instance %d" % i
instRange = ""

# separate ranges at spaces
f = frames.split(" ")

# separate individual start, end, and increment values
for p in f:
c = p.split(",")
incr = 1
if len(c) > 0:
start = int(c[0])
end = start
if len(c) > 1: end = int(c[1])
if len(c) > 2: incr = int(c[2])

# re-jigger this range for this instance of the renderer
st = start + ( i * incr )
en = end
inc = incr * inst
new = "%d,%d,%d" % (st, en, inc)
if inc == 1:
new = "%d,%d" % (st, en)
if en == st:
new = "%d" % st
if st > en:
new = ""
else:
# add the re-jiggered range to the instances range string
instRange = instRange + " " + new

print ">>> range for instance %d is: %s" % (i, instRange)

logFile = "%s/%s_log%02d.log" % (scriptpath, scriptname, i)

cmd = "%s %s %s/%s %s > %s &" % (nuke.EXE_PATH, flags, scriptpath, scriptname, instRange, logFile)
print ">>> starting instance %d" % (i, )
print "command: " + cmd
os.system(cmd)

DrJones
January 20th, 2009, 01:50 AM
thank you tim.bowman

works a treat, we got our code dude to set up a button and menu for the script.

I have attached

-DrJones

DrJones
January 20th, 2009, 10:45 PM
Hi tim

loving your script...

but I was thinking is there a way to set up a watch folder thing that would be looking for the final frame to be rendered, once this has occurred it would trigger a read node with the just rendered footage which then in turn would trigger a FrameCycler.

any pointers would be great.

-DrJones

p.s. I will PM you also just incase your not subscribed

tim.bowman
January 21st, 2009, 01:02 PM
That'd be a pretty neat trick. You probably noticed that the script saves logfiles for each renderer. It should be possible to monitor those to detect when each of them has completed it's last frame. Adding the Read and launching FrameCycler should be rather elementary.

Gentle Fury
January 21st, 2009, 01:04 PM
Hi tim

loving your script...

but I was thinking is there a way to set up a watch folder thing that would be looking for the final frame to be rendered, once this has occurred it would trigger a read node with the just rendered footage which then in turn would trigger a FrameCycler.

any pointers would be great.

-DrJones

p.s. I will PM you also just incase your not subscribed


Actually, something I found out a while ago on accident is that if you framecycle the output node it will use your render...no need to read it in. Awesomely useful trick!

DrJones
January 21st, 2009, 06:51 PM
One question about framecycler can it be launched out side of the Nuke UI...

is there some thing I need to set up to be able to trigger it via terminal or even a desktop icon??

tim.bowman
January 21st, 2009, 07:29 PM
One question about framecycler can it be launched out side of the Nuke UI...

is there some thing I need to set up to be able to trigger it via terminal or even a desktop icon??

If you are talking about the FrameCycler that comes with Nuke, it cannot be launched from outside Nuke. But if you bought it separately from IRIDAS, then you will be able to launch it from the command line.

I just had a thought... maybe you could launch a new instance of Nuke in terminal mode and pass it the command to launch FrameCycler. Could be something to try.

DrJones
January 21st, 2009, 07:35 PM
yeah

thats a cool idea, get that work and then set up a permeant alias=framecycler and so on.

-DrJones

nidas
January 22nd, 2009, 07:27 AM
Does this work on windows?

I canīt get it to work on my win XP...

I get the button in Nuke and I can choose how many instances and frames, but then nothing happens...

Any ideas?

DrJones
January 22nd, 2009, 06:55 PM
I will test it on a windows box, but first and for most do you have a Write node in your script.

-DrJones

nidas
January 23rd, 2009, 02:23 AM
I have a Write node in my script that I tried...

Thanks for taking time to help me!

nastaca
January 27th, 2009, 08:03 AM
Hi there!!
Thanks guys very usefull stuff !!!
is there any news about win version?
--
regards
--
n

DrJones
January 27th, 2009, 09:25 AM
Have not test but should work in winTel

In version 5.1v3 the multi core perfomance has been improved (not tested yet)

This may change things but an update is coming.

On another note mr russ adrerson has released a 64 bit ver of syntheyes ( a one man band) so why is the foundry being so so so spake, and what happened to external monitoring.

-DrJones

DrJones
January 27th, 2009, 09:27 AM
This above post refers to mac os x

DrJones
January 27th, 2009, 06:52 PM
Ok I spoke to soon, it does not work on windows..

I was not thinking straight when I said that it should of course it wont.

having a look at it today.

davemcd
February 12th, 2009, 07:29 PM
The script sort of works on windows but and its a big one... Each cmd process waits in line for the previous one to finish before it launches, so in effect it launches one process does all the frames returns 0 the the script then goes through the second iteration of the loop launching the second bunch of frames... also it locks me out of nuke while it does the frames.

I'm pretty new when it comes to python but I did find this:
http://docs.python.org/library/subprocess.html#module-subprocess

Effectively the os.system(cmd) line should be replaced with the subprocess calls. I had a quick play but only had moderate success, I got it to execute one process but with errors not locking me out of nuke but still couldnt figure out how to get multiple shells going. I'm assuming there is a way to get it to launch each process but not wait for a return before continuing...

Anyone got any good ideas?

DaveMcD

Furnace
February 18th, 2009, 11:55 PM
I hacked up a really botchy script for myself to do this kind of stuff on Windows. Essentially all it does is write the required command line arguments to a .bat file that is then launched using os.startfile(). Nuke isn't locked either when using os.startfile(). I also use this command to launch the Windows Calculator in Nuke (really old keyboard woo).

The required directories are also created using the .bat file, and it deletes itself which for some reason amuses me :D

Seems to work (in a really rudimentary way) though I haven't bothered investigating setting the parameters for threads etc. as I'm only on a 2 CPU machine, but it should be no problem if you wanted to.

I hope this helps, let me know if you need to know some other commands, I'm just hacking stuff together and am a lazy programmer, if it works, I don't normally investigate why or add in any error checking or anything ;)

tim.bowman
April 16th, 2009, 09:49 AM
I'm pretty new when it comes to python but I did find this:
http://docs.python.org/library/subprocess.html#module-subprocess


Good catch on the subprocess module. I wrote this before I knew os.command was deprecated. If I should actually get some free time (don't hold your breath), I'd love to rewrite launchNukes using subprocess.

Until that happens, if anyone else has some free time and the inclination to do it, you have my blessing as long as you post the updated code here for all to use.

col_jin
December 3rd, 2009, 03:54 PM
I am on a a nuke 5.2.2 on osx.
I've been trying to install this script, and I couldn't find the "toolbars.py" script to modify.
And when I tried to use script editor, it does not work. Please help =)