Hi,
I am trying to script event plugin for rendering Quicktimes after Nuke job with Deadline 8. Unfortunately, Draft doesn’t seem to have functionality I need (mostly metadata handling), so I decided to spawn another Nuke script for Quicktime creation.
Is there a recommended way how to import module nuke in the event plugin?
What is the best way to stop the event to propagate, so I do not try to create quicktime from quicktime from quicktime…
Thank you !
Here is my code so far…
[code]import re, os
from System.IO import *
from System.Text import *
from Deadline.Events import *
from Deadline.Scripting import *
######################################################################
This is the function that Deadline calls to get an instance of the
main DeadlineEventListener class.
######################################################################
def GetDeadlineEventListener():
return MyEvent()
def CleanupDeadlineEventListener( eventListener ):
eventListener.Cleanup()
######################################################################
This is the main DeadlineEventListener class for MyEvent.
######################################################################
class MyEvent (DeadlineEventListener):
def __init__( self ):
self.OnJobFinishedCallback += self.OnJobFinished
def Cleanup( self ):
del self.OnJobFinishedCallback
def OnJobFinished( self, job ):
# Only submit a dailies job for finished Nuke jobs
if job.JobPlugin != "Nuke":
return None
else:
# output filenames
outputDirectories = job.JobOutputDirectories
outputFilenames = job.JobOutputFileNames
if len( outputFilenames ) == 0:
self.LogInfo( "ERROR: Could not find a full output path in Job properties; No Draft job will be created." )
# frame range
frames = []
for frame in job.Frames:
frames.append(frame)
sortedInputFrameList = sorted(frames)
inputFrameList = FrameUtils.ToFrameString(frames) # not sure what is this for...
try:
first = int(sortedInputFrameList[0])
last = int(sortedInputFrameList[-1])
except:
first = 0
last = 0
framesList = str(first) + ' - ' + str(last)
self.LogInfo( "Dailies render range: " + framesList)
# for every nuke output (writer)
for i in range(len(outputDirectories)):
outputFullPath = ( ('%s/%s') % (outputDirectories[i], outputFilenames[i]))
outputFullPath = self.replaceCounterSign(outputFullPath, 0).replace('\\', '/') # the replace // can be problem in paths with server names...
self.LogInfo( "Output sequence %d : %s" % (i, outputFullPath))
_scriptname = outputDirectories[i] + '/' + outputFilenames[i] + '_NukeDailies.nk'
self.LogInfo( "_scriptname: " + _scriptname)
"""
import nuke
nuke.scriptNew()
nuke.scriptSave(_scriptname)
_filepath = outputDirectories[i] + '/' + outputFilenames[i]
self.LogInfo( "_filepath: " + _filepath)
r = nuke.createNode('Read', 'file ' + _filepath)
r.knob('first').setValue(first)
r.knob('last').setValue(last)
r.knob('origfirst').setValue(first)
r.knob('origlast').setValue(last)
nuke.scriptSave(_scriptname)
"""
# create job info file
jobInfoFilename = Path.Combine(ClientUtils.GetDeadlineTempPath(), "nuke_job_info.job")
writer = StreamWriter(jobInfoFilename, False, Encoding.Unicode)
writer.WriteLine("Plugin=Nuke")
writer.WriteLine("Name=NukeDailies")
writer.WriteLine("Comment=Autosubmitted after Nuke job...")
writer.WriteLine("Frames=%s" % job.JobFrames)
writer.Close()
# create plugin info file
_scriptname = "Z:/rendertest/rendertest_A.nk"
pluginInfoFilename = Path.Combine(ClientUtils.GetDeadlineTempPath(), "nuke_plugin_info.job" )
writer = StreamWriter(pluginInfoFilename, False, Encoding.Unicode)
writer.WriteLine("SceneFile=%s" % _scriptname)
writer.WriteLine("Version=10") # nuke version
writer.Close()
# submit nuke script
exitCode = ClientUtils.ExecuteCommand( (jobInfoFilename, pluginInfoFilename) )
def replaceCounterSign(self, path, mode, extraStringBeforeCounter = ''):
''' Replaces counter-like string in path with other type of counterstring. Known counters: %04d (printf notation), multiple #s, multiple ?s. Optionally can insert custom string before the counter.'''
if re.search('#+', path):
counterString = re.search('#+', path).group()
counterLength = len(counterString)
elif re.search('\?+', path):
counterString = re.search('\?+', path).group()
counterLength = len(counterString)
elif re.search('%0\dd+', path):
counterString = re.search('%0\dd', path).group()
counterLength = int(counterString.replace('%0', '').replace('d', ''))
if mode == 0: # gives back printf notation
newCounter = '%%0%dd' % counterLength
elif mode == 1: # gives back multiple # signs
newCounter = ('#'* counterLength)
elif mode == 2: # gives back multiple ? signs
newCounter = ('?'* counterLength)
elif mode == 3: # replaces counter with empty string
newCounter = ''
newCounter = extraStringBeforeCounter + newCounter # inserting extra string before the counter
replacedPath = path.replace(counterString, newCounter)
return replacedPath
[/code]