AWS Thinkbox Discussion Forums

Submitting a command line Job via Maxscript

Hello there

I want to submit a CMD Job via Maxscript. We have a custom submitter here and I want to add the option to generate a psd file out of the finished renderoutput tif files (in one folder). I would use ImageMagick for that and use a command line to control it. This cmd job also needs to be dependent from the batch tile job sent right before (I would do that via SMTDSettings.SubmitAsDependent etc… if it’s still working that way for a cmd job)

I could not find anything useful on the interwebs regarding something like that, I hope someone here can help me :slight_smile:
thanks in Advance,
Alex

Hi there,

The easiest way of doing this will be from an event. You can set events to trigger at various times - in your case, it’ll be at the end of a job. Events are basically just Python scripts that run when the trigger occurs and include the ability to access all the job that triggered its setting. So I suspect what you’ll want is the event Python to do something like check what type of job triggered it, and if it was a Draft job then gather any information it needs to (ie the render output path) and use this to format the correct command to send to deadlinecommand.exe and then use Python to execute this (using Popen, probably).

That’s pretty much it. The Deadline event environment offers a whole bunch of existing functions from Deadline that can do useful stuff like return the various job settings to you, give you the repo root etc.

Dan

Thanks! This sounds exactly like the stuff I want

I do have the *.bat file in place now, the only thing Deadline needs to do now is to fire it up from the Renderoutput Folder when ‘OnJobFinishedCallback’ from the TileAssembly Job kicks in… the only sad thing is - I still dont know Python :frowning:

So I kindly have to ask for help… I dont know where to start even :frowning:

So wat I managed to do so far is creating this custom event with py and param file.

what I need is something like

def OnJobFinished( self, job, outputIndex=0):
# TODO: Connect to pipeline site to notify it that the job for a particular
# shot or task is complete.
import subprocess

outputDirectories = job.JobOutputDirectories
    jobOutputDir = outputDirectories[outputIndex]
	
	if job.Frames = 1:
		self.LogInfo( "now the batch will be executed" )
		subprocess.call([jobOutputDir+generate_this_psb.bat]) 
    pass

but of course it does not work

ok.

I had some help (somewhere else) - but yet, I only get this in the console

2019-05-14 19:10:16:  WARNING: Exception in CleanupDeadlineEventListener: TypeError : OnJobFinished() takes at least 2 arguments (1 given) (FranticX.Scripting.PythonNetException)
2019-05-14 19:10:16:    File "none", line 21, in CleanupDeadlineEventListener
2019-05-14 19:10:16:  [stack trace (maximumDepth=4)]   FranticX.Diagnostics.Trace2.WriteStack    line 0
2019-05-14 19:10:16:     FranticX.Diagnostics.Trace2.Warning    line 0
2019-05-14 19:10:16:     FranticX.Diagnostics.Trace2.Warning    line 0
2019-05-14 19:10:16:     Deadline.Events.DeadlineEventPlugin.Dispose    line 0

yet I only used the base code from here

https://docs.thinkboxsoftware.com/products/deadline/7.1/1_User%20Manual/manual/event-plugins.html

my code:

from Deadline.Events import *
import subprocess
import os
import platform

######################################################################
## This is the function that Deadline calls to get an instance of the
## main DeadlineEventListener class.
######################################################################
def GetDeadlineEventListener():
    return MyEvent()

######################################################################
## This is the function that Deadline calls when the event plugin is
## no longer in use so that it can get cleaned up.
######################################################################
def CleanupDeadlineEventListener( deadlinePlugin ):
    deadlinePlugin.Cleanup()

######################################################################
## This is the main DeadlineEventListener class for MyEvent.
######################################################################
class MyEvent (DeadlineEventListener):

    def __init__( self ):
        # Set up the event callbacks here
        self.OnJobSubmittedCallback += self.OnJobSubmitted
        self.OnJobFinishedCallback += self.OnJobFinished

    def Cleanup( self ):
        del self.OnJobSubmittedCallback
        del self.OnJobFinishedCallback

    def OnJobSubmitted( self, job ):
        # TODO: Connect to pipeline site to notify it that a job has been submitted
        # for a particular shot or task.
        pass

    def OnJobFinished( self, job ):
        # TODO: Connect to pipeline site to notify it that the job for a particular
        # shot or task is complete.

        outputDirectories = job.JobOutputDirectories
        jobOutputDir = outputDirectories[outputIndex]

        self.LogInfo('!!! now the batch will be executed on computer ' + platform.node())
        self.LogInfo(Job.JobExtraInfo0())
        #subprocess.call([jobOutputDir+'generate_this_psb.bat']) 

        call = subprocess.Popen([jobOutputDir+'generate_this_psb.bat'],stdout=subprocess.PIPE,stderr=subprocess.PIPE,universal_newlines=True)
        callresult = call.communicate()[0].decode('utf-8').splitlines()
        batchResults = [row.strip() for row in callresult]					
        self.LogInfo(batchResults)
        
        self.LogInfo('!!! end of execution') 
        
        
        retval = call.returncode
        
        pass

does anyone have any idea please?

Privacy | Site terms | Cookie preferences