.. _DeadlineIntegration/ConvertAFrameStringToFrameList:

Convert a Frame String to Frame List
====================================

Problem
-------

Deadline passes frames to Draft in the form of a Frame Range (such as ``"1-100"``).  Converting this to a List of Frame Numbers can be non-trivial, given how complex Frame Strings can get (e.g., ``"105,200-400x3,500-600step4,1-100"`` is a valid Frame String).

Solution
--------

Fortunately, we have added a function in Draft's :mod:`DraftParamParser` helper script specifically to alleviate this problem::

    import Draft
    from DraftParamParser import * #Needed to use the utility function

    #Sample input
    frameRange = "1-10x2,11-15" #Equivalent to 1,3,5,7,9,11,12,13,14,15

    frameList = FrameRangeToFrames( frameRange )

    #You can now iterate over the Frame List
    for frameNumber in frameList:
        #Do something with the FrameNumber
        print frameNumber

Discussion
----------

In addition to the obvious functionality of expanding a Frame Range string into a list of Frames, the :func:`~DraftParamParser.FrameRangeToFrames` function also sorts the frames in ascending order and ensures that there are no duplicate frames in the List.

Simple Frame Ranges
-------------------

It should be noted that Deadline also passes the First and Last frames in the given Frame Range as separate arguments to Draft (``startFrame`` and ``endFrame``, respectively).  If you're not interested in supporting complex Frame Ranges in your Template, you can simply use these values to generate a list of frames as follows::

    for frameNumber in range( startFrame, endFrame + 1 ):
        #Do something with frameNumber
        print frameNumber
