Hi.
We are using Deadline 5.1. For the submission script, I noticed that we have 2 scripts doing about the same thing. Probably one for the menu, and one for the right-click context menu. So here it is :
\fx-deadline\Deadline\scripts\Submission\DeliveriesSubmission\DeliveriesSubmission.py
[code]#Python.Net
from System.Collections.Specialized import *
from System.IO import *
from System.Text import *
from System.Diagnostics import *
from Deadline.Scripting import *
from System import Array
import re, sys, os
########################################################################
Globals
########################################################################
scriptDialog = None
settings = None
shotgunSettings = {}
versionID = None
deadlineJobID = None
startup = True
updatingInputFile = False
#get the path to the Shotgun events folder, and import the ShotgunUtils module
shotgunPath = Path.Combine( RepositoryUtils.GetEventsDirectory(), “Shotgun” )
sys.path.append( shotgunPath )
import ShotgunUtils
########################################################################
Main Function Called By Deadline
########################################################################
def main( *args ):
global scriptDialog
global settings
global shotgunPath
global startup
global versionID
global deadlineJobID
dialogWidth = 550
dialogHeight = 650
labelWidth = 120
controlWidth = 152
tabWidth = dialogWidth - 16
tabHeight = dialogHeight - 50
scriptDialog = DeadlineScriptEngine.GetScriptDialog()
scriptDialog.SetSize( dialogWidth, dialogHeight )
scriptDialog.SetTitle( "Submit Draft Script To Deadline" )
scriptDialog.SetIcon( Path.Combine( GetRootDirectory(), "scripts/Submission/DraftSubmission/DraftSubmission.ico" ) )
#~ scriptDialog.AddTabControl("Job Options Tabs", tabWidth+8, tabHeight)
#~ scriptDialog.AddTabPage("Job Options")
scriptDialog.AddControl( "JobOptionsSeparator", "SeparatorControl", "Job Description", tabWidth - 16, -1 )
scriptDialog.AddRow()
scriptDialog.AddControl( "NameLabel", "LabelControl", "Job Name", labelWidth, -1 )
scriptDialog.AddControl( "NameBox", "TextControl", "Untitled", tabWidth - labelWidth - 24, -1 )
scriptDialog.EndRow()
scriptDialog.AddRow()
scriptDialog.AddControl( "CommentLabel", "LabelControl", "Comment", labelWidth, -1 )
scriptDialog.AddControl( "CommentBox", "TextControl", "", tabWidth - labelWidth - 24, -1 )
scriptDialog.EndRow()
scriptDialog.AddRow()
scriptDialog.AddControl( "DepartmentLabel", "LabelControl", "Department", labelWidth, -1 )
scriptDialog.AddControl( "DepartmentBox", "TextControl", "", tabWidth - labelWidth - 24, -1 )
scriptDialog.EndRow()
scriptDialog.AddControl( "Separator2", "SeparatorControl", "Job Options", tabWidth - 16, -1 )
scriptDialog.AddRow()
scriptDialog.AddControl( "PoolLabel", "LabelControl", "Pool", labelWidth, -1 )
scriptDialog.AddControl( "PoolBox", "PoolComboControl", "none", controlWidth, -1 )
scriptDialog.EndRow()
scriptDialog.AddRow()
scriptDialog.AddControl( "GroupLabel", "LabelControl", "Group", labelWidth, -1 )
scriptDialog.AddControl( "GroupBox", "GroupComboControl", "none", controlWidth, -1 )
scriptDialog.EndRow()
scriptDialog.AddRow()
scriptDialog.AddControl( "PriorityLabel", "LabelControl", "Priority", labelWidth, -1 )
scriptDialog.AddRangeControl( "PriorityBox", "RangeControl", 50, 0, 100, 0, 1, controlWidth, -1 )
scriptDialog.EndRow()
scriptDialog.AddRow()
scriptDialog.AddControl( "TaskTimeoutLabel", "LabelControl", "Task Timeout", labelWidth, -1 )
scriptDialog.AddRangeControl( "TaskTimeoutBox", "RangeControl", 0, 0, 1000000, 0, 1, controlWidth, -1 )
scriptDialog.AddSelectionControl( "IsBlacklistBox", "CheckBoxControl", False, "Machine List Is A Blacklist", 200, -1 )
scriptDialog.EndRow()
scriptDialog.AddRow()
scriptDialog.AddControl( "MachineListLabel", "LabelControl", "Machine List", labelWidth, -1 )
scriptDialog.AddControl( "MachineListBox", "MachineListControl", "", tabWidth - labelWidth - 24, -1 )
scriptDialog.EndRow()
scriptDialog.AddRow()
scriptDialog.AddControl( "LimitGroupLabel", "LabelControl", "Limits", labelWidth, -1 )
scriptDialog.AddControl( "LimitGroupBox", "LimitGroupControl", "", tabWidth - labelWidth - 24, -1 )
scriptDialog.EndRow()
scriptDialog.AddRow()
scriptDialog.AddControl( "DependencyLabel", "LabelControl", "Dependencies", labelWidth, -1 )
scriptDialog.AddControl( "DependencyBox", "DependencyControl", "", tabWidth - labelWidth - 24, -1 )
scriptDialog.EndRow()
scriptDialog.AddRow()
scriptDialog.AddControl( "OnJobCompleteLabel", "LabelControl", "On Job Complete", labelWidth, -1 )
scriptDialog.AddControl( "OnJobCompleteBox", "OnJobCompleteControl", "Nothing", controlWidth, -1 )
scriptDialog.AddSelectionControl( "SubmitSuspendedBox", "CheckBoxControl", False, "Submit Job As Suspended", 200, -1 )
scriptDialog.EndRow()
scriptDialog.AddControl( "DraftOptionsSeparator", "SeparatorControl", "Draft Options", tabWidth - labelWidth - 16, -1 )
scriptDialog.AddRow()
scriptDialog.AddControl( "ScriptLabel", "LabelControl", "Draft Script", labelWidth, -1 )
scriptDialog.AddSelectionControl( "ScriptBox", "FileBrowserControl", "", "Draft Scripts (*.py)|*.py|All Files (*.*)|*.*", tabWidth - labelWidth - 24, -1 )
scriptDialog.EndRow()
scriptDialog.AddRow()
scriptDialog.AddControl( "InputLabel", "LabelControl", "Input File", labelWidth, -1 )
inputBox = scriptDialog.AddSelectionControl( "InputBox", "FileBrowserControl", "", "Input File All Files (*.*)|*.*", tabWidth - labelWidth - 24, -1 )
inputBox.ValueModified += InputImagesModified
scriptDialog.EndRow()
scriptDialog.AddRow()
scriptDialog.AddControl( "OutputLabel", "LabelControl", "Output File", labelWidth, -1 )
scriptDialog.AddSelectionControl( "OutputBox", "FileSaverControl", "", "Output File All Files (*.*)|*.*", tabWidth - labelWidth - 24, -1 )
scriptDialog.EndRow()
scriptDialog.AddRow()
scriptDialog.AddControl( "FrameListLabel", "LabelControl", "Frame List", labelWidth, -1 )
scriptDialog.AddControl( "FrameListBox", "TextControl", "", controlWidth, -1 )
scriptDialog.EndRow()
scriptDialog.AddRow()
scriptDialog.AddControl( "UserLabel", "LabelControl", "User", labelWidth, -1 )
scriptDialog.AddControl( "UserBox", "TextControl", "", tabWidth - labelWidth - 24, -1 )
scriptDialog.EndRow()
scriptDialog.AddRow()
scriptDialog.AddControl( "EntityLabel", "LabelControl", "Entity", labelWidth, -1 )
scriptDialog.AddControl( "EntityBox", "TextControl", "", tabWidth - labelWidth - 24, -1 )
scriptDialog.EndRow()
scriptDialog.AddRow()
scriptDialog.AddControl( "VersionLabel", "LabelControl", "Version", labelWidth, -1 )
scriptDialog.AddControl( "VersionBox", "TextControl", "", tabWidth - labelWidth - 24, -1 )
scriptDialog.EndRow()
scriptDialog.AddRow()
scriptDialog.AddControl( "ArgsLabel", "LabelControl", "Additional Args", labelWidth, -1 )
scriptDialog.AddControl( "ArgsBox", "TextControl", "", tabWidth - labelWidth - 24, -1 )
scriptDialog.EndRow()
scriptDialog.AddRow()
scriptDialog.AddControl( "DummyLabel0", "Labelcontrol", "", labelWidth, -1 )
# only show this button if we're not submitting from shotgun (it's redundant if we are)
if ( len(args) == 0 ) or ( args[0] != 'fromshotgun' ) :
sgConnectButton = scriptDialog.AddControl( "ShotgunConnectButton", "ButtonControl", "Use Shotgun Data...", controlWidth, -1 )
sgConnectButton.ValueModified += SGConnectButtonPressed
scriptDialog.AddSelectionControl( "UploadOutputBox", "CheckboxControl", False, "Upload Output to Shotgun", 200, -1 )
scriptDialog.SetEnabled( "UploadOutputBox", False )
scriptDialog.EndRow()
scriptDialog.AddRow()
scriptDialog.AddControl( "DummyLabel1", "LabelControl", "", dialogWidth - 232, -1 )
submitButton = scriptDialog.AddControl( "SubmitButton", "ButtonControl", "Submit", 100, -1 )
submitButton.ValueModified += SubmitButtonPressed
closeButton = scriptDialog.AddControl( "CloseButton", "ButtonControl", "Close", 100, -1 )
closeButton.ValueModified += CloseButtonPressed
scriptDialog.EndRow()
fromShotgun = ( len(args) > 0 ) and ( args[0] == 'fromshotgun' )
if not fromShotgun:
#load up sticky shotgun settings
LoadShotgunSettings()
#Load regular sticky settings after shotgun settings (so that regular sticky settings have priority over Shotgun sticky settings)
settings = ("DepartmentBox","PoolBox","GroupBox","PriorityBox","IsBlacklistBox","MachineListBox","LimitGroupBox","ScriptBox","InputBox","OutputBox","FrameListBox","UserBox","EntityBox","VersionBox","ArgsBox")
scriptDialog.LoadSettings( GetSettingsFilename(), settings )
# if called from shotgun, set initial vals (higher priority than sticky settings)
if fromShotgun:
versionID = None
try:
versionID = int( args[1].split('=')[1] )
except:
scriptDialog.ShowMessageBox( "Got an invalid Version ID from Shotgun. You will have to select the Shotgun Version manually.", "Error" )
if versionID != None:
version = ShotgunUtils.GetVersion( versionID, shotgunPath )
dlinit = ShotgunUtils.GetIniFileData( shotgunPath )
pathField = dlinit['VersionEntityPathToFramesField']
firstFrameField = dlinit['VersionEntityFirstFrameField']
lastFrameField = dlinit['VersionEntityLastFrameField']
jobIDField = dlinit.get('VersionEntityJobIDField', '' )
scriptDialog.SetValue( "UserBox", version['user']['login'] )
scriptDialog.SetValue( "EntityBox", version['entity']['name'] )
scriptDialog.SetValue( "VersionBox", version['code'] )
scriptDialog.SetValue( "InputBox", version[pathField] )
jobID = version.get( jobIDField, '' )
if jobID != '':
deadlineJobID = jobID
InputImagesModified()
scriptDialog.SetValue( "FrameListBox", "%s-%s" % (version[firstFrameField], version[lastFrameField]) )
scriptDialog.SetValue('NameBox', 'Shotgun Draft Job')
scriptDialog.SetValue( 'UploadOutputBox', True )
scriptDialog.LoadTooltips( Path.Combine( GetRootDirectory(), "scripts/Submission/DraftSubmission/Tooltips.ini" ) )
startup = False
scriptDialog.ShowDialog( False )
def LoadShotgunSettings():
settingsFile = GetShotgunSettingsFilename()
if File.Exists( settingsFile ):
ProcessShotgunLines( File.ReadAllLines( settingsFile ), False )
def GetShotgunSettingsFilename():
return Path.Combine( GetDeadlineSettingsPath(), “DraftSettingsShotgun.ini” )
def SGConnectButtonPressed( *args ):
global shotgunSettings
shotgunScript = Path.Combine( GetRootDirectory(), "events/Shotgun/ShotgunUI.py" )
output = ClientUtils.ExecuteCommandAndGetOutput( ("-ExecuteScript", shotgunScript, "DraftMonitor", "SelectVersion") )
ProcessShotgunLines( output.splitlines(), True )
def ProcessShotgunLines( lines, connectButtonPressed ):
global shotgunSettings
global scriptDialog
global versionID
tempKVPs = {}
for line in lines:
line = line.strip()
tokens = line.split( '=', 1 )
if len( tokens ) > 1:
key = tokens[0]
value = tokens[1]
tempKVPs[key] = value
if len( tempKVPs ) > 0:
shotgunSettings = tempKVPs
versionID = shotgunSettings.get( 'VersionId', None )
template = shotgunSettings.get( "DraftTemplate", "" )
if template.strip() != "None" and template.strip() != "":
scriptDialog.SetValue( "ScriptBox", shotgunSettings["DraftTemplate"] )
scriptDialog.SetValue( "UserBox", shotgunSettings.get( "UserName", "" ) )
scriptDialog.SetValue( "EntityBox", shotgunSettings.get( "EntityName", "" ) )
scriptDialog.SetValue( "VersionBox", shotgunSettings.get( "VersionName", "" ) )
scriptDialog.SetValue( "InputBox", shotgunSettings.get( "PathToFrames", "" ) )
firstFrame = shotgunSettings.get( "FirstFrame", "" )
lastFrame = shotgunSettings.get( "LastFrame", "" )
if ( firstFrame.strip() != "" and lastFrame.strip() != "" ):
scriptDialog.SetValue( "FrameListBox", "%s-%s" % (firstFrame, lastFrame) )
scriptDialog.SetEnabled( "UploadOutputBox", True )
File.WriteAllLines( GetShotgunSettingsFilename(), tuple(lines) )
def InputImagesModified(*args):
global startup
global updatingInputFile
if not updatingInputFile:
try:
filename = scriptDialog.GetValue( "InputBox" )
if filename != "":
initFrame = FrameUtils.GetFrameNumberFromFilename( filename )
paddingSize = FrameUtils.GetPaddingSizeFromFilename( filename )
startFrame = 0
endFrame = 0
outputFilename = ""
if paddingSize > 0:
filename = FrameUtils.GetLowerFrameFilename( filename, initFrame, paddingSize )
updatingInputFile = True
scriptDialog.SetValue( "InputBox", filename )
updatingInputFile = False
startFrame = FrameUtils.GetLowerFrameRange( filename, initFrame, paddingSize )
endFrame = FrameUtils.GetUpperFrameRange( filename, initFrame, paddingSize )
(outputFilename, oldExt) = os.path.splitext( FrameUtils.GetFilenameWithoutPadding( filename ) )
outputFilename = outputFilename.rstrip( "_.- " ) + ".mov"
else:
outputFilename = Path.ChangeExtension( filename,'.mov' )
outputFilename = outputFilename.replace( Path.GetFileName(outputFilename), 'Draft\\' + Path.GetFileName(outputFilename) )
scriptDialog.SetValue( "FrameListBox", "%s-%s" % (startFrame, endFrame) )
scriptDialog.SetValue( "OutputBox", outputFilename )
scriptDialog.SetValue( "NameBox", Path.GetFileNameWithoutExtension( outputFilename ) )
except:
pass
def GetSettingsFilename():
return Path.Combine( GetDeadlineSettingsPath(), “DraftSettings.ini” )
def CloseDialog():
global scriptDialog
global settings
scriptDialog.SaveSettings( GetSettingsFilename(), settings )
scriptDialog.CloseDialog()
def CloseButtonPressed(*args):
CloseDialog()
def SubmitButtonPressed(*args):
global scriptDialog
global versionID
global deadlineJobID
# Check if Draft files exist.
sceneFile = scriptDialog.GetValue("ScriptBox")
if( not File.Exists( sceneFile ) ):
scriptDialog.ShowMessageBox( "Cannot find Draft script '%s'" % sceneFile, "Error" )
return
outputFile = scriptDialog.GetValue( "OutputBox" )
if ( outputFile.strip() == "" ):
scriptDialog.ShowMessageBox( "No output file was specified. Please fill in an output location.", "Error" )
return
inFile = scriptDialog.GetValue("InputBox")
if ( PathUtils.IsPathLocal(inFile) ):
result = scriptDialog.ShowMessageBox( "The input file location '%s' is local. Are you sure you want to continue?" % inFile, "Warning", ("Yes","No") )
if(result=="No"):
return
outputDirectory = Path.GetDirectoryName( outputFile )
if ( not Directory.Exists( outputDirectory ) ):
result = scriptDialog.ShowMessageBox( "The selected output directory '%s' does not exist.\n\nDo you wish to create this directory now?" % outputDirectory, "Warning", ("Yes","No") )
if ( result == "Yes" ):
Directory.CreateDirectory( outputDirectory )
#some apps use '?' instead of '#' to mark frame padding
inFile = re.sub( "\?", "#", inFile )
#make sure the padding isn't swapped out already
if ( not "#" in inFile ):
paddingString = ""
for i in range( 0, FrameUtils.GetPaddingSizeFromFilename( inFile ) ):
paddingString += "#"
inFile = FrameUtils.SubstituteFrameNumber( inFile, paddingString )
# Create job info file.
jobInfoFilename = Path.Combine( GetDeadlineTempPath(), "draft_job_info.job" )
writer = StreamWriter( jobInfoFilename, False, Encoding.Unicode )
try:
writer.WriteLine( "Plugin=Draft" )
writer.WriteLine( "Name=%s" % scriptDialog.GetValue( "NameBox" ) )
writer.WriteLine( "Comment=%s" % scriptDialog.GetValue( "CommentBox" ) )
writer.WriteLine( "Department=%s" % scriptDialog.GetValue( "DepartmentBox" ) )
writer.WriteLine( "Pool=%s" % scriptDialog.GetValue( "PoolBox" ) )
writer.WriteLine( "Group=%s" % scriptDialog.GetValue( "GroupBox" ) )
writer.WriteLine( "Priority=%s" % scriptDialog.GetValue( "PriorityBox" ) )
writer.WriteLine( "TaskTimeoutMinutes=%s" % scriptDialog.GetValue( "TaskTimeoutBox" ) )
writer.WriteLine( "LimitGroups=%s" % scriptDialog.GetValue( "LimitGroupBox" ) )
writer.WriteLine( "JobDependencies=%s" % scriptDialog.GetValue( "DependencyBox" ) )
writer.WriteLine( "OnJobComplete=%s" % scriptDialog.GetValue( "OnJobCompleteBox" ) )
writer.WriteLine( "Frames=0" )
#writer.WriteLine( "ChunkSize=1" )
writer.WriteLine( "ChunkSize=%s" % scriptDialog.GetValue( "ChunkSizeBox" ) )
writer.WriteLine( "OutputFilename0=%s\n" % scriptDialog.GetValue( "OutputBox" ) )
if( bool(scriptDialog.GetValue( "IsBlacklistBox" )) ):
writer.WriteLine( "Blacklist=%s" % scriptDialog.GetValue( "MachineListBox" ) )
else:
writer.WriteLine( "Whitelist=%s" % scriptDialog.GetValue( "MachineListBox" ) )
if( bool(scriptDialog.GetValue( "SubmitSuspendedBox" )) ):
writer.WriteLine( "InitialStatus=Suspended" )
finally:
writer.Close()
# Create plugin info file.
pluginInfoFilename = Path.Combine( GetDeadlineTempPath(), "draft_plugin_info.job" )
writer = StreamWriter( pluginInfoFilename, False, Encoding.Unicode )
try:
writer.WriteLine( "scriptFile=%s" % scriptDialog.GetValue( "ScriptBox" ) )
#prep the script arguments
args = []
args.append( 'username="%s" ' % scriptDialog.GetValue( "UserBox" ) )
args.append( 'entity="%s" ' % scriptDialog.GetValue( "EntityBox" ) )
args.append( 'version="%s" ' % scriptDialog.GetValue( "VersionBox" ) )
frames = FrameUtils.Parse( scriptDialog.GetValue( "FrameListBox" ) )
args.append( 'frameList=%s ' % scriptDialog.GetValue( "FrameListBox" ) )
args.append( 'startFrame=%s ' % str(frames[0]) )
args.append( 'endFrame=%s ' % str(frames[-1]) )
args.append( 'outFile="%s" ' % scriptDialog.GetValue( "OutputBox" ) )
args.append( 'inFile="%s" ' % inFile )
args.append( 'ConcurrentTasks=8')
if deadlineJobID != None:
args.append( 'deadlineJobID="%s"' % deadlineJobID )
args.append( scriptDialog.GetValue( "ArgsBox" ) )
#write out the params to the plugin info file
i = 0
for scriptArg in args:
writer.WriteLine( "ScriptArg%d=%s" % ( i, scriptArg ) )
i += 1
if ( scriptDialog.GetValue("UploadOutputBox") ) :
if versionID != None:
scriptArgs = "\"" + Path.Combine( Path.Combine( RepositoryUtils.GetEventsDirectory(), "Shotgun" ), "ShotgunUtils.py" ) + "\""
scriptArgs += " " + "Upload"
scriptArgs += " " + str(versionID)
scriptArgs += " \"" + scriptDialog.GetValue("OutputBox") + "\""
writer.WriteLine( "postRenderScript=%s" % scriptArgs )
else:
scriptDialog.ShowMessageBox( "The 'Upload to Shotgun' option has been selected, but no Shotgun version has been selected.\n\nPlease select a Shotgun version (by clicking 'Use Shotgun Data...') or de-select this option.", "Error" )
return
finally:
writer.Close()
# Setup the command line arguments.
arguments = StringCollection()
arguments.Add( "-notify" )
arguments.Add( jobInfoFilename )
arguments.Add( pluginInfoFilename )
arguments.Add( sceneFile )
# Now submit the job.
ScriptUtils.ExecuteCommand( arguments )
[/code]
\fx-deadline\Deadline\scripts\Jobs\JobDeliveriesSubmission\JobDeliveriesSubmission.py
[code]#Python.NET
import os, sys, re
from System.Collections.Specialized import *
from System.IO import *
from System.Text import *
from Deadline.Scripting import *
from Deadline.Jobs import *
from FranticX.Utils import *
scriptDialog = None
sgVersionId = None
settings = None
updatingInputFile = False
job = None
def main( *args ):
global scriptDialog
global settings
dialogWidth = 550
dialogHeight = 600
labelWidth = 120
controlWidth = 152
tabWidth = dialogWidth
tabHeight = dialogHeight - 50
scriptDialog = DeadlineScriptEngine.GetScriptDialog()
scriptDialog.SetSize( dialogWidth, dialogHeight )
scriptDialog.SetTitle( "Submit DPX Deliveries To Deadline" )
scriptDialog.SetIcon( os.path.join( GetRootDirectory(), "scripts/Submission/DeliveriesSubmission/DeliveriesSubmission.ico" ) )
scriptDialog.AddControl( "JobOptionsSeparator", "SeparatorControl", "Job Description", tabWidth - 16, -1 )
scriptDialog.AddRow()
scriptDialog.AddControl( "NameLabel", "LabelControl", "Job Name", labelWidth, -1 )
scriptDialog.AddControl( "NameBox", "TextControl", "Untitled", tabWidth - labelWidth - 24, -1 )
scriptDialog.EndRow()
scriptDialog.AddRow()
scriptDialog.AddControl( "CommentLabel", "LabelControl", "Comment", labelWidth, -1 )
scriptDialog.AddControl( "CommentBox", "TextControl", "", tabWidth - labelWidth - 24, -1 )
scriptDialog.EndRow()
scriptDialog.AddRow()
scriptDialog.AddControl( "DepartmentLabel", "LabelControl", "Department", labelWidth, -1 )
scriptDialog.AddControl( "DepartmentBox", "TextControl", "", tabWidth - labelWidth - 24, -1 )
scriptDialog.EndRow()
scriptDialog.AddControl( "Separator2", "SeparatorControl", "Job Options", tabWidth - 16, -1 )
scriptDialog.AddRow()
scriptDialog.AddControl( "PoolLabel", "LabelControl", "Pool", labelWidth, -1 )
scriptDialog.AddControl( "PoolBox", "PoolComboControl", "none", controlWidth, -1 )
scriptDialog.EndRow()
scriptDialog.AddRow()
scriptDialog.AddControl( "GroupLabel", "LabelControl", "Group", labelWidth, -1 )
scriptDialog.AddControl( "GroupBox", "GroupComboControl", "none", controlWidth, -1 )
scriptDialog.EndRow()
scriptDialog.AddRow()
scriptDialog.AddControl( "PriorityLabel", "LabelControl", "Priority", labelWidth, -1 )
scriptDialog.AddRangeControl( "PriorityBox", "RangeControl", 50, 0, 100, 0, 1, controlWidth, -1 )
scriptDialog.EndRow()
scriptDialog.AddRow()
scriptDialog.AddControl( "TaskTimeoutLabel", "LabelControl", "Task Timeout", labelWidth, -1 )
scriptDialog.AddRangeControl( "TaskTimeoutBox", "RangeControl", 0, 0, 1000000, 0, 1, controlWidth, -1 )
scriptDialog.AddSelectionControl( "IsBlacklistBox", "CheckBoxControl", False, "Machine List Is A Blacklist", 200, -1 )
scriptDialog.EndRow()
scriptDialog.AddRow()
scriptDialog.AddControl( "MachineListLabel", "LabelControl", "Machine List", labelWidth, -1 )
scriptDialog.AddControl( "MachineListBox", "MachineListControl", "", tabWidth - labelWidth - 24, -1 )
scriptDialog.EndRow()
scriptDialog.AddRow()
scriptDialog.AddControl( "LimitGroupLabel", "LabelControl", "Limits", labelWidth, -1 )
scriptDialog.AddControl( "LimitGroupBox", "LimitGroupControl", "", tabWidth - labelWidth - 24, -1 )
scriptDialog.EndRow()
scriptDialog.AddRow()
scriptDialog.AddControl( "DependencyLabel", "LabelControl", "Dependencies", labelWidth, -1 )
scriptDialog.AddControl( "DependencyBox", "DependencyControl", "", tabWidth - labelWidth - 24, -1 )
scriptDialog.EndRow()
scriptDialog.AddRow()
scriptDialog.AddControl( "OnJobCompleteLabel", "LabelControl", "On Job Complete", labelWidth, -1 )
scriptDialog.AddControl( "OnJobCompleteBox", "OnJobCompleteControl", "Nothing", controlWidth, -1 )
scriptDialog.AddSelectionControl( "SubmitSuspendedBox", "CheckBoxControl", False, "Submit Job As Suspended", 200, -1 )
scriptDialog.EndRow()
scriptDialog.AddControl( "DraftOptionsSeparator", "SeparatorControl", "Delivery Options", tabWidth - labelWidth - 16, -1 )
'''
scriptDialog.AddRow()
scriptDialog.AddControl( "QuickTimeTemplateLabel", "LabelControl", "", labelWidth, -1 )
scriptDialog.AddSelectionControl( "QtSubmitBox", "CheckBoxControl", False, "Submit Quicktime Creation", 200, -1 )
scriptDialog.EndRow()
'''
scriptDialog.AddRow()
scriptDialog.AddControl( "InputLabel", "LabelControl", "Input File", labelWidth, -1 )
inputBox = scriptDialog.AddSelectionControl( "InputBox", "FileBrowserControl", "", "Input File All Files (*.*)|*.*", tabWidth - labelWidth - 24, -1 )
inputBox.ValueModified += InputImagesModified
scriptDialog.EndRow()
scriptDialog.AddRow()
scriptDialog.AddControl( "ScriptLabel", "LabelControl", "Quicktime Template", labelWidth, -1 )
scriptDialog.AddSelectionControl( "ScriptBox", "FileBrowserControl", "", "Draft Scripts (*.py)|*.py|All Files (*.*)|*.*", tabWidth - labelWidth - 24, -1 )
scriptDialog.EndRow()
'''
scriptDialog.AddRow()
scriptDialog.AddControl( "OutputLabel", "LabelControl", "Output File", labelWidth, -1 )
scriptDialog.AddSelectionControl( "OutputBox", "FileSaverControl", "", "Output File All Files (*.*)|*.*", tabWidth - labelWidth - 24, -1 )
scriptDialog.EndRow()
'''
scriptDialog.AddRow()
scriptDialog.AddControl( "FrameListLabel", "LabelControl", "Frame List", labelWidth, -1 )
scriptDialog.AddControl( "FrameListBox", "TextControl", "", controlWidth, -1 )
scriptDialog.AddSelectionControl( "QtSubmitBox", "CheckBoxControl", False, "Submit Quicktime Creation Job", 200, -1 )
#scriptDialog.AddSelectionControl( "SGUploadBox", "CheckBoxControl", False, "Upload Output To Shotgun", controlWidth, -1 )
#scriptDialog.SetEnabled( "SGUploadBox", False )
scriptDialog.EndRow()
scriptDialog.AddRow()
scriptDialog.AddControl( "ChunkSizeLabel", "LabelControl", "Frames Per Task", labelWidth, -1 )
scriptDialog.AddRangeControl( "ChunkSizeBox", "RangeControl", 1, 1, 1000000, 0, 1, 106, -1 )
scriptDialog.EndRow()
scriptDialog.AddControl( "OptionalParametersSeparator", "SeparatorControl", "Optional Delivery Parameters", tabWidth - labelWidth - 16, -1 )
'''
scriptDialog.AddRow()
scriptDialog.AddControl( "UserLabel", "LabelControl", "User", labelWidth, -1 )
scriptDialog.AddControl( "UserBox", "TextControl", "", tabWidth - labelWidth - 24, -1 )
scriptDialog.EndRow()
'''
scriptDialog.AddRow()
scriptDialog.AddControl( "EntityLabel", "LabelControl", "Entity", labelWidth, -1 )
scriptDialog.AddControl( "EntityBox", "TextControl", "", tabWidth - labelWidth - 24, -1 )
scriptDialog.EndRow()
'''
scriptDialog.AddRow()
scriptDialog.AddControl( "VersionLabel", "LabelControl", "Version", labelWidth, -1 )
scriptDialog.AddControl( "VersionBox", "TextControl", "", tabWidth - labelWidth - 24, -1 )
scriptDialog.EndRow()
'''
scriptDialog.AddRow()
scriptDialog.AddControl( "ArgsLabel", "LabelControl", "Additional Args", labelWidth, -1 )
scriptDialog.AddControl( "ArgsBox", "TextControl", "", tabWidth - labelWidth - 24, -1 )
scriptDialog.EndRow()
scriptDialog.AddRow()
scriptDialog.AddControl( "DummyLabel1", "LabelControl", "", dialogWidth - 232, -1 )
submitButton = scriptDialog.AddControl( "SubmitButton", "ButtonControl", "Submit", 100, -1 )
submitButton.ValueModified += SubmitButtonPressed
closeButton = scriptDialog.AddControl( "CloseButton", "ButtonControl", "Close", 100, -1 )
closeButton.ValueModified += CloseButtonPressed
scriptDialog.EndRow()
settings = ("DepartmentBox", "CategoryBox", "PoolBox", "GroupBox", "PriorityBox", "IsBlacklistBox", "MachineListBox", "ChunkSizeBox", "LimitGroupBox", "ArgsBox")
scriptDialog.LoadSettings( GetSettingsFilename(), settings )
LoadDefaults()
scriptDialog.ShowDialog( False )
#This functions fills in default values based on the selected job
def LoadDefaults():
global scriptDialog
global sgVersionId
global updatingInputFile
global job
job = MonitorUtils.GetSelectedJobs()[0]
#check for shotgun
if job.GetJobExtraInfoKeyValue( 'VersionId' ) != "" and job.ExtraInfo5 != "":
sgVersionId = job.GetJobExtraInfoKeyValue( 'VersionId' )
scriptDialog.SetValue( 'EntityBox', job.ExtraInfo2 )
#scriptDialog.SetValue( 'VersionBox', job.ExtraInfo3 )
#scriptDialog.SetValue( 'UserBox', job.ExtraInfo5 )
#scriptDialog.SetEnabled( 'SGUploadBox', True )
#scriptDialog.SetValue( 'SGUploadBox', True )
else:
sgVersionId = None
#scriptDialog.SetValue( 'UserBox', job.UserName )
scriptDialog.SetValue( 'EntityBox', job.Name )
inputFile = ""
outputFile = ""
if len(job.OutputDirectories) > 0:
inputFile = job.OutputDirectories[0]
inputFile = RepositoryUtils.CheckPathMapping( inputFile, False )
inputFile = PathUtils.ToPlatformIndependentPath( inputFile )
outputFile = os.path.join( inputFile, "Draft" )
if len(job.OutputFileNames) > 0:
inputFile = os.path.join( inputFile, job.OutputFileNames[0] )
inputFile = re.sub( "\?", "#", inputFile )
(tempFileName, oldExt) = os.path.splitext( job.OutputFileNames[0] )
tempFileName = re.sub( "[\?#]", "", tempFileName ).rstrip( "_.- " )
outputFile = os.path.join( outputFile, tempFileName + ".mov" )
updatingInputFile = True
scriptDialog.SetValue( 'InputBox', inputFile )
updatingInputFile = False
#scriptDialog.SetValue( 'OutputBox', outputFile )
scriptDialog.SetValue( 'DependencyBox', job.JobId )
frameList = FrameListUtils.ToString( job.Frames )
scriptDialog.SetValue( 'FrameListBox', frameList )
scriptDialog.SetValue( 'NameBox', job.Name + " [DPX DELIVERY]" )
def InputImagesModified(*args):
global updatingInputFile
if not updatingInputFile:
try:
filename = scriptDialog.GetValue( "InputBox" )
if filename != "":
initFrame = FrameUtils.GetFrameNumberFromFilename( filename )
paddingSize = FrameUtils.GetPaddingSizeFromFilename( filename )
startFrame = 0
endFrame = 0
outputFilename = ""
if paddingSize > 0:
filename = FrameUtils.GetLowerFrameFilename( filename, initFrame, paddingSize )
updatingInputFile = True
scriptDialog.SetValue( "InputBox", filename )
updatingInputFile = False
startFrame = FrameUtils.GetLowerFrameRange( filename, initFrame, paddingSize )
endFrame = FrameUtils.GetUpperFrameRange( filename, initFrame, paddingSize )
(outputFilename, oldExt) = os.path.splitext( FrameUtils.GetFilenameWithoutPadding( filename ) )
outputFilename = outputFilename.rstrip( "_.- " ) + ".mov"
else:
outputFilename = Path.ChangeExtension( filename,'.mov' )
outputFilename = outputFilename.replace( Path.GetFileName(outputFilename), 'Draft/' + Path.GetFileName(outputFilename) )
scriptDialog.SetValue( "FrameListBox", str(startFrame) + "-" + str(endFrame) )
#scriptDialog.SetValue( "OutputBox", outputFilename )
scriptDialog.SetValue( "NameBox", Path.GetFileNameWithoutExtension( outputFilename ) )
except:
pass
def GetSettingsFilename():
return Path.Combine( GetDeadlineSettingsPath(), “DraftSettings.ini” )
def CloseDialog():
global scriptDialog
global settings
scriptDialog.SaveSettings( GetSettingsFilename(), settings )
scriptDialog.CloseDialog()
def CloseButtonPressed( * args ):
CloseDialog()
def SubmitButtonPressed( *args ):
global scriptDialog
global job
# Check if Draft files exist.
#sceneFile = scriptDialog.GetValue("ScriptBox")
#dpxTemplate = '//fx-nas-01/vfx/RENDER/DRAFT/slate/SLATE_DeliveriesConversion.py'
dpxTemplate = '//fx-nas-01/vfx/RENDER/DRAFT/slate/TEMPLATE_DpxDeliveries.py'
if ( dpxTemplate == "" ):
scriptDialog.ShowMessageBox( "Please select a Draft Template.", "Error" )
return
elif( not File.Exists( dpxTemplate ) ):
scriptDialog.ShowMessageBox( "Cannot find Draft script '%s'" % dpxTemplate, "Error" )
return
elif( PathUtils.IsPathLocal( dpxTemplate ) ):
result = scriptDialog.ShowMessageBox( "The Draft Template's location '%s' is local.\n\nAre you sure you want to continue?" % dpxTemplate, "Warning", ("Yes","No") )
if(result=="No"):
return
if ( not FrameUtils.FrameRangeValid( scriptDialog.GetValue( "FrameListBox" ) ) ):
scriptDialog.ShowMessageBox( "Invalid Frame List specified.\n\nPlease enter a valid Frame range." )
return
inFile = scriptDialog.GetValue("InputBox").replace('\\','/')
#outputDirectory = Path.GetDirectoryName( scriptDialog.GetValue( "OutputBox" ) )
dlvFolder = os.path.join('/'.join(inFile.replace('\\','/').split('/')[:-4]), 'dlv').replace('\\','/')
if not os.path.exists(dlvFolder):
os.makedirs(dlvFolder)
versions = []
for each in os.listdir(dlvFolder):
if os.path.isdir(os.path.join(dlvFolder, each)):
if each[0] == 'v' and len(each)==3:
versions.append(each)
if not versions:
outVersion = 'v01'
else:
versions.sort()
oLastVersion = re.search( '\d{2}', versions[-1]).group()
outVersion = 'v%02d'%(int(oLastVersion)+1)
outputDirectory = os.path.join(dlvFolder, outVersion)
if ( PathUtils.IsPathLocal(inFile) ):
result = scriptDialog.ShowMessageBox( "The input file location '%s' is local.\n\nAre you sure you want to continue?" % inFile, "Warning", ("Yes","No") )
if(result=="No"):
return
elif ( PathUtils.IsPathLocal( outputDirectory ) ):
result = scriptDialog.ShowMessageBox( "The output directory '%s' is local.\n\nAre you sure you want to continue?" % inFile, "Warning", ("Yes","No") )
if(result=="No"):
return
if ( not Directory.Exists( outputDirectory ) ):
result = scriptDialog.ShowMessageBox( "The selected output directory '%s' does not exist.\n\nDo you wish to create this directory now?" % outputDirectory, "Warning", ("Yes","No") )
if ( result == "Yes" ):
Directory.CreateDirectory( outputDirectory )
if ( not "#" in inFile ):
paddingString = ""
for i in range( 0, FrameUtils.GetPaddingSizeFromFilename( inFile ) ):
paddingString += "#"
inFile = FrameUtils.SubstituteFrameNumber( inFile, paddingString ).replace('\\','/')
# Create job info file.
jobInfoFilename = Path.Combine( GetDeadlineTempPath(), "draft_job_info.job" )
writer = StreamWriter( jobInfoFilename, False, Encoding.Unicode )
try:
writer.WriteLine( "Plugin=Draft" )
#writer.WriteLine( "version=2.7" )
writer.WriteLine( "Name=%s" % scriptDialog.GetValue( "NameBox" ) )
writer.WriteLine( "Comment=%s" % scriptDialog.GetValue( "CommentBox" ) )
writer.WriteLine( "Department=%s" % scriptDialog.GetValue( "DepartmentBox" ) )
writer.WriteLine( "Pool=%s" % scriptDialog.GetValue( "PoolBox" ) )
writer.WriteLine( "Group=%s" % scriptDialog.GetValue( "GroupBox" ) )
writer.WriteLine( "Priority=%s" % scriptDialog.GetValue( "PriorityBox" ) )
writer.WriteLine( "TaskTimeoutMinutes=%s" % scriptDialog.GetValue( "TaskTimeoutBox" ) )
writer.WriteLine( "LimitGroups=%s" % scriptDialog.GetValue( "LimitGroupBox" ) )
writer.WriteLine( "JobDependencies=%s" % scriptDialog.GetValue( "DependencyBox" ) )
writer.WriteLine( "OnJobComplete=%s" % scriptDialog.GetValue( "OnJobCompleteBox" ) )
writer.WriteLine( "Frames=%s" % scriptDialog.GetValue( "FrameListBox" ) )
writer.WriteLine( "ChunkSize=%s" % scriptDialog.GetValue( "ChunkSizeBox" ) )
#writer.WriteLine( "OutputFilename0=%s\n" % scriptDialog.GetValue( "OutputBox" ) )
if( bool(scriptDialog.GetValue( "IsBlacklistBox" )) ):
writer.WriteLine( "Blacklist=%s" % scriptDialog.GetValue( "MachineListBox" ) )
else:
writer.WriteLine( "Whitelist=%s" % scriptDialog.GetValue( "MachineListBox" ) )
if( bool(scriptDialog.GetValue( "SubmitSuspendedBox" )) ):
writer.WriteLine( "InitialStatus=Suspended" )
finally:
writer.Close()
# Create plugin info file.
pluginInfoFilename = Path.Combine( GetDeadlineTempPath(), "draft_plugin_info.job" )
writer = StreamWriter( pluginInfoFilename, False, Encoding.Unicode )
try:
#prep the script arguments
args = []
args.append( 'username="FrimaFX" ' )
args.append( 'entity="%s" ' % scriptDialog.GetValue( 'EntityBox' ) )
#args.append( 'version="%s" ' % scriptDialog.GetValue( 'VersionBox' ) )
args.append( 'inFile="%s" ' % inFile )
#args.append( 'outFile="%s" ' % scriptDialog.GetValue( "OutputBox" ) )
args.append( 'outFolder="%s" ' % outputDirectory)
frames = FrameUtils.Parse(scriptDialog.GetValue( "FrameListBox" ))
args.append( 'startFrame="%s" ' % frames[0] )
args.append( 'endFrame="%s" ' % frames[-1] )
args.append( 'frameList="%s" ' % scriptDialog.GetValue( "FrameListBox" ) )
args.append( 'ConcurrentTasks=8')
args.append( 'deadlineJobID=%s ' % job.JobId )
args.append( scriptDialog.GetValue( "ArgsBox" ) )
#write out the params to the file
writer.WriteLine( "scriptFile=%s" % dpxTemplate )
i = 0
for scriptArg in args:
writer.WriteLine( "ScriptArg%d=%s" % ( i, scriptArg ) )
i += 1
'''
if ( scriptDialog.GetValue("SGUploadBox") ):
if sgVersionId != None:
scriptArgs = "\"" + os.path.join( RepositoryUtils.GetEventsDirectory(), "Shotgun", "ShotgunUtils.py" ) + "\""
scriptArgs += " Upload"
scriptArgs += " " + str(sgVersionId)
scriptArgs += " \"" + scriptDialog.GetValue("OutputBox") + "\""
writer.WriteLine( "postRenderScript=%s" % scriptArgs )
else:
scriptDialog.ShowMessageBox( "The 'Upload to Shotgun' option has been selected, but no Shotgun version has been found.", "Error" )
return
'''
finally:
writer.Close()
# Setup the command line arguments.
arguments = StringCollection()
arguments.Add( "-notify" )
arguments.Add( jobInfoFilename )
arguments.Add( pluginInfoFilename )
arguments.Add( dpxTemplate )
# Now submit the job.
ScriptUtils.ExecuteCommand( arguments )
CloseDialog()
[/code]
Draft Template : \fx-nas-01\vfx\RENDER\DRAFT\slate\TEMPLATE_DpxDeliveries.py
[code]import os
import sys
import shutil
import re
import datetime
import copy
import xml.etree.ElementTree as xml
import Draft
from DraftParamParser import *
#print “Draft Version: %s” % Draft.LibraryInfo.Version()
#CHANGE ME! Path to the Deadline Repository root
deadlineRepo = “//fx-deadline/deadline/”
#CHANGE ME! Path to an image containing the background of the slate frame
slateFrame = “//fx-deadline/deadline/Draft/Slate_Montage5K_new.png”
logoFrame = “//fx-deadline/deadline/Draft/FrimaFX.png”
#The argument name/types we’re expecting from the command line arguments
expectedTypes = dict()
expectedTypes[‘frameList’] = ‘’
expectedTypes[‘inFile’] = ‘’
expectedTypes[‘outFolder’] = ‘’
expectedTypes[‘username’] = ‘’
expectedTypes[‘entity’] = ‘’
expectedTypes[‘taskStartFrame’] = ‘’
expectedTypes[‘taskEndFrame’] = ‘’
#Parse the command line arguments
params = ParseCommandLine( expectedTypes, sys.argv )
inFilePattern = params[‘inFile’]
#params[‘frameList’] = “%d-%d” % (params[‘startFrame’], params[‘endFrame’])
frames = range( params[‘taskStartFrame’], params[‘taskEndFrame’] + 1 )
if(True):
inDir, inOriginalFile = os.path.split(params[‘inFile’])
inBase, inExt = os.path.splitext(inOriginalFile)
inDir = inDir.replace('\\','/')
inVersion = inDir.split('/')[-1]
dpxOutDir = os.path.join(params['outFolder'], 'dpx')
exrOutDir = os.path.join(params['outFolder'], 'exr')
if not os.path.exists(os.path.join(dpxOutDir, 'left')):
os.makedirs(os.path.join(dpxOutDir, 'left'))
if not os.path.exists(os.path.join(dpxOutDir, 'right')):
os.makedirs(os.path.join(dpxOutDir, 'right'))
if not os.path.exists(os.path.join(exrOutDir, 'left')):
os.makedirs(os.path.join(exrOutDir, 'left'))
if not os.path.exists(os.path.join(exrOutDir, 'right')):
os.makedirs(os.path.join(exrOutDir, 'right'))
dpxLut = Draft.LUT.CreateCineon()
for eye in [‘l’,‘r’]:
#Build up the encoders
doOutSingleEye = False
if not ‘%v’ in inBase:
doOutSingleEye = True
outBaseEye = inBase.replace(’%v’, eye)
if eye == 'r':
side = 'right'
else:
side = 'left'
#Main encoding loop
for frameNumber in frames:
print("Processing Frame: %d...-1" % frameNumber)
inFile = inFilePattern.replace('%v', eye)
inFile = ReplaceFilenameHashesWithNumber(inFile, frameNumber)
# Copy EXR to deliveries directory
shutil.copy(inFile, os.path.join(exrOutDir, side))
# Convert EXR to DPX and copy DPX to DPX deliveries directory
dpxOutput = Draft.Image.ReadFromFile(inFile)
dpxLut.Apply(dpxOutput)
dpxOutput.WriteToFile(os.path.join(dpxOutDir, side, '%s.dpx'%os.path.splitext(os.path.basename(inFile))[0]))
if doOutSingleEye:
break
[/code]
It is probably something trivial, but I’m not sure where to search…
Thanks
Maxime