2

I am trying to send maya renders to render farm by Deadline Software.

Python Command for Manual Job Submission Maya to deadline.

import sys
import subprocess
import maya.cmds as cmds

deadline = "C:\\Program Files\\Thinkbox\\Deadline\\bin\\deadlinecommand.exe"
maya_exe = "C:\\Program Files\\Autodesk\\Maya2015\\bin\\render.exe"

file_path = cmds.file(q=True, location=True)

command = '%s ' \
          '-SubmitCommandLineJob ' \
          '-executable "%s" ' \
          '-name "File Name" ' \
          '"%s" ' % (deadline, maya_exe, file_path)
process = subprocess.Popen(command, stdout=subprocess.PIPE)
lines_iterator = iter(process.stdout.readline, b"")
for line in lines_iterator:
    print(line)
    sys.stdout.flush()

any python ways to add maya renders to deadline..?

Rajiv Sharma
  • 6,746
  • 1
  • 52
  • 54
  • unrelated: 1- you could use `r'C:\Program..'` instead of `'C:\\Program..'`—notice the `r''` prefix (it is a raw string literal). 2- Use implicit line-continuation inside parentheses instead of backslashes and named format vars for readability: `command = ('{deadline} ' '...' '.. "{maya_exe}"' ... '"{file_path}"').format(**vars())` 3- You don't need to redirect the output if all you do is echo it to stdout: drop `stdout=PIPE` and use just `subprocess.check_call(command)`. || What is your question? How to reproduce the command in your question but without `deadlinecommand` program? – jfs May 24 '16 at 08:37
  • @J.F.Sebastian Thanks for sharing the awesome python tips. i am trying to launch/submit maya file to deadline render farm by python. – Rajiv Sharma May 24 '16 at 08:51
  • 1
    what issue do you have with your current script? What do you expect to happen? What happens instead? (describe step by step). If you get any errors; include them in your question as is. Mention what software versions do you use (OS, python, etc). [edit] the question and put the info there. I don't know what *"submit maya file to deadline render farm by python"* but this info may help others to answer the question. – jfs May 24 '16 at 09:00

2 Answers2

1

I had written an exporter for nuke jobs inside maya. It should work with maya too (even if I don't understand you you are not using the deadline script - note that deadline for nuke has a submitter in .py):

There is two parts file I was editing with xml : nuke_submit_info.job nuke_plugin_info.job Find the same files for maya and it should do the trick

And then submitting them with 'deadlinecommand'

def sumbit2deadline():
    FileName = "nuke_submit_info"
    JobInfo = PathSaveFiles + FileName + ".job"
    FileName = "nuke_plugin_info"
    JobPlugIn = PathSaveFiles + FileName + ".job"
    FileName = "NukeTemplate"
    JobFile = PathSaveFiles + FileName + ".nk"
    command = "deadlinecommand" + " " + JobInfo + " " + JobPlugIn + " " + JobFile
    subprocess.Popen(command)
DrWeeny
  • 2,487
  • 1
  • 14
  • 17
1

Finally, I got the way to send maya render jobs to deadline render farm software. all we need to do is write 2 job files for deadline. 1. maya_deadline_job.job 2. maya_deadline_info.job

and pass these files as arguments in deadlinecommand.exe for example:

deadlinecommand.exe "maya_deadline_info.job"  "maya_deadline_info.job"

Here is my python code

"""
This script will submit current file to deadline for render
"""
import os
import sys
import subprocess
import maya.cmds as cmds


def maya_deadline_job():
    """
    this function will collect scene file information and write a job file
    :return:
    """
    renderer_name = 'File'
    version = cmds.about(version=True)
    project_path = cmds.workspace(q=True, directory=True)
    width = cmds.getAttr("defaultResolution.width")
    height = cmds.getAttr("defaultResolution.height")
    output_file_path = cmds.workspace(expandName="images")
    output_file_prefix = cmds.getAttr("defaultRenderGlobals.imageFilePrefix")
    scene_file = cmds.file(q=True, location=True)
    info_txt = 'Animation=1\n' \
               'Renderer={}\n' \
               'UsingRenderLayers=0\n' \
               'RenderLayer=\n' \
               'RenderHalfFrames=0\n' \
               'LocalRendering=0\n' \
               'StrictErrorChecking=1\n' \
               'MaxProcessors=0\n' \
               'AntiAliasing=low\n' \
               'Version={}\n' \
               'Build=64bit\n' \
               'ProjectPath={}\n' \
               'ImageWidth={}\n' \
               'ImageHeight={}\n' \
               'OutputFilePath={}\n' \
               'OutputFilePrefix={}\n' \
               'Camera=\n' \
               'Camera0=\n' \
               'Camera1=RENDERShape\n' \
               'Camera2=frontShape\n' \
               'Camera3=perspShape\n' \
               'Camera4=sideShape\n' \
               'Camera5=topShape\n' \
               'SceneFile={}\n' \
               'IgnoreError211=0'.format(renderer_name
                                         version,
                                         project_path,
                                         width,
                                         height,
                                         output_file_path,
                                         output_file_prefix,
                                         scene_file)

    maya_deadline_job_file = r'{}\maya_deadline_job.job'.format(os.getenv('TEMP'))
    with open(maya_deadline_job_file, 'w') as job_file:
        job_file.write(info_txt)
    return maya_deadline_job_file


def maya_deadline_info():
    """
    this function will collect maya deadline information and write a job file
    :return:
    """
    info_txt = 'Plugin=MayaBatch\n' \
               'Name=MY_FILE_NAME\n' \
               'Comment=Render Launch by Python\n' \
               'Pool=none\n' \
               'MachineLimit=0\n' \
               'Priority=50\n' \
               'OnJobComplete=Nothing\n' \
               'TaskTimeoutMinutes=0\n' \
               'MinRenderTimeMinutes=0\n' \
               'ConcurrentTasks=1\n' \
               'Department=\n' \
               'Group=none\n' \
               'LimitGroups=\n' \
               'JobDependencies=\n' \
               'InitialStatus=Suspended\n' \
               'OutputFilename0=C:/Users/raijv/Documents/maya/projects/default/images/masterLayer_2.iff.????\n' \
               'Frames=1-10\n' \
               'ChunkSize=1'

    maya_deadline_info_file = r'{}\maya_deadline_info.job'.format(os.getenv('TEMP'))
    with open(maya_deadline_info_file, 'w') as job_file:
        job_file.write(info_txt)
    return maya_deadline_info_file


def submit_to_deadline():
    """
    this function will send current scene to deadline for rendering
    :return:
    """
    deadline_cmd = r"C:\Program Files\Thinkbox\Deadline\bin\deadlinecommand.exe"
    job_file = maya_deadline_job()
    info_file = maya_deadline_info()
    command = '{deadline_cmd} "{job_file}" "{info_file}"'.format(**vars())
    process = subprocess.Popen(command, stdout=subprocess.PIPE)
    lines_iterator = iter(process.stdout.readline, b"")
    #  Lets print the output log to see the Error / Success 
    for line in lines_iterator:
        print(line)
        sys.stdout.flush()

submit_to_deadline()

Edit info -

Do not use cmds.getAttr("defaultRenderGlobals.currentRenderer" in renderer_name variable. use File that will take layers overide renderer.

Rajiv Sharma
  • 6,746
  • 1
  • 52
  • 54