Job scripts and Dependency scripts can use Python to implement additional automation. Job scripts can be used to perform additional tasks during rendering, and Dependency scripts can control when jobs start rendering.
Note that because the Python scripts will be executed in a non-interactive way, it is important that your scripts do not contain any blocking operations like infinite loops, or interfaces that require user input. See the Scripting Overview documentation for more information, and links to the Deadline Scripting reference.
Job scripts can be assigned to Jobs in order to automate certain tasks before a Job starts rendering (Pre-Job Script), after a Job finished rendering (Post-Job Script), or before and after each individual Job Task has been completed (Pre and Post-Task Scripts).
After you create your scripts, you can assign them to a Job by right-clicking on the desired Job in the Monitor, and selecting ‘Modify Job Properties’. The script options can be found under the ‘Scripts’ section of the Job Properties window. In addition to this, Job scripts can be specified by custom submitters by including them in the Job Info File on submission. Note that a full path to the script is required, so it is recommended that the script file be stored in a location that is accessible to all Workers.
Creating Job Scripts¶
The only requirement for a Job script is that you define a __main__ function. This is the function that will be called by Deadline when it comes time to execute the script, and an instance of the DeadlinePlugin object will be passed as a parameter.
def __main__( *args ): #Replace "pass" pass
A common use for Post-Task scripts is to do some processing with the output image files. Here is a sample script that demonstrates how to get the output file names for the current task, and print them out to the render log:
import re from System.IO import * from Deadline.Scripting import * def __main__( *args ): deadlinePlugin = args job = deadlinePlugin.GetJob() outputDirectories = job.OutputDirectories outputFilenames = job.OutputFileNames paddingRegex = re.compile("[^\\?#]*([\\?#]+).*") for i in range( 0, len(outputDirectories) ): outputDirectory = outputDirectories[i] outputFilename = outputFilenames[i] startFrame = deadlinePlugin.GetStartFrame() endFrame = deadlinePlugin.GetEndFrame() for frameNum in range(startFrame, endFrame+1): outputPath = Path.Combine(outputDirectory,outputFilename) outputPath = outputPath.replace("//","/") m = re.match(paddingRegex,outputPath) if( m != None): padding = m.group(1) frame = StringUtils.ToZeroPaddedString(frameNum,len(padding),False) outputPath = outputPath.replace( padding, frame ) deadlinePlugin.LogInfo( "Output file: " + outputPath )
Dependency scripts can be used to control when a job starts rendering. For example, the script could connect to an internal pipeline database to see if the job has been approved to start rendering.
After you create your dependency scripts, you can assign them to a Job by right-clicking on the desired Job in the Monitor, and selecting ‘Modify Job Properties’. The Script Dependencies options can be found under the ‘Scripts’ section of the Job Properties window. In addition to this, Job scripts can be specified by custom submitters by including them in the Job Info File on submission. Note that a full path to the script is required, so it is recommended that the script file be stored in a location that is accessible to all Workers.
Creating Dependency Scripts¶
The only requirement for a Dependency script is that you define a __main__ function. This is the function that will be called by Deadline when it comes time to execute the script to determine if a job should be released or not.
For jobs without Frame Dependencies enabled, only the job ID will be passed as a parameter. The __main__ function should then return True if the job should be released or False if it shouldn’t be.
For jobs with Frame Dependencies enabled, the job ID will be passed as the first parameter, and a list of pending task IDs will be passed as the second parameter. The __main__ function should then return the list of task IDs that should be released, or an empty list of none should be released.
Here is a very simple example that will work regardless of whether Frame Dependencies are enabled or not:
def __main__( jobId, taskIds=None ): if not taskIds: # Frame Dependencies are disabled releaseJob = False #figure out if job should be released return releaseJob else: # Frame Dependencies are enabled tasksToRelease =  #figure out which tasks should be released, and append their IDs to the array return tasksToRelease
By giving the taskIds parameter a default of None, it allows the script to function regardless of whether Frame Dependencies are enabled or not. You can check if “taskIds” is None, and if it is, you know that Frame Dependencies are disabled.
Migrating Scripts from Deadline 5¶
Some changes were made to the Scripting API in Deadline 6, which means that Deadline 6 and later are NOT backward compatible with scripts written for Deadline 5. However, migrating your scripts over is relatively straightforward, and this guide will walk you through the API changes so that you can update your scripts as necessary.
The only significant change is that the globally defined functions are no longer available. See the Code Completion for the Deadline Scripting API section in the Scripting Overview documentation for more information, including replacement functions.