How to get current Task frame number

I have a python script that is executed within a maya scene file at render time (it’s a VRay post translate python script). I need to know the frame number being rendered, which isn’t necessarily the current frame of the maya scene. I was hoping to get this information from the deadline Task. Is there a way to get the Frame or Task information in this context? Does deadline set any environment variables for frame or task info?

I was able to get the frame number by using deadlinecommand to get the current job and task info for the host computer. Here’s the python code for those that are interested.

import socket
import re
from subprocess import Popen, PIPE


def deadlinecommand(cmd, *args):
    cmds = ['deadlinecommand', cmd]
    if args:
        for arg in args:
            if arg is not None:
                if isinstance(arg, (tuple, list)):
                    flag, value = arg
                    if value is not None:
                        if isinstance(value, bool):
                            if value is True:
                                cmds.append(flag)
                        else:
                            cmds.extend([flag, value])
                else:
                    cmds.append(unicode(arg))

    p = Popen(cmds, stdout=PIPE, stderr=PIPE)
    stdout, stderr = p.communicate()
    return stdout.rstrip()


def get_slave(slave_names, use_ini_display=False):
    """
    Display information for the slave

    :param slave_names: The slave name, or a list of slave names separated
                        by commas
    :param use_ini_display: true/false (optional, default is false)

    """
    return deadlinecommand('GetSlave', slave_names, use_ini_display)


def get_job_task(job_id, task_id):
    """
    Display the specified task for the job

    :param job_id: The job ID
    :param task_id: The task ID

    """
    return deadlinecommand('GetJobTask', job_id, task_id)


def get_render_task_frame():
    host = socket.gethostname()
    jobid = None
    taskids = None
    frame = None
    
    slave_info = get_slave(host)
    match_job = re.search(r'^CurrentJobId=([0-9a-z]*)\s*$', slave_info, flags=re.M)
    match_task = re.search(r'^CurrentTaskIds=([\d,]*)\s*$', slave_info, flags=re.M)
    if match_job and match_task:
        jobid = match_job.group(1) or None
        taskids = match_task.group(1).split(',')
        
    if jobid and taskids:
        task_info = get_job_task(jobid, taskids[0])
        match_frames = re.search(r'TaskFrameList=([\d,]*)\s*$', task_info, flags=re.M)
        if match_frames:
            frames = match_frames.group(1).split(',')
            if frames:
                frame = frames[0]
    
    return frame

Hello,

Posting here what I replied to on your support ticket. This should still work, even if you had multiple slaves on a single machine, as each slave name is different, and you could address the proper one that way. Thanks for posting it to the forums in case others need to know.

This works fantasticlly…as long as I don’t have concurrent tasks above 1. As soon as I have 2 or more concurrent tasks, The frame number I get back from deadline is the lowest of the frame numbers currently running on that machine. Is there a way to do a pre-task script that would be able to get the frame number for the task itself?