Skip to content

utils

get_frame_from_filename(filename)

Return sequence number from Flame path style

Parameters:

Name Type Description Default
filename str

file name

required

Returns:

Type Description

Optional[str]: sequence frame number if found or None

Example

def get_frame_from_filename(path): ("plate.0001.exr") > "0001"

Source code in client/ayon_flame/otio/utils.py
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
def get_frame_from_filename(filename):
    """
    Return sequence number from Flame path style

    Args:
        filename (str): file name

    Returns:
        Optional[str]: sequence frame number if found or None

    Example:
        def get_frame_from_filename(path):
            ("plate.0001.exr") > "0001"

    """
    _, ext = os.path.splitext(filename)

    if ext.lower() not in IMAGE_EXTENSIONS:
        return None

    pattern = re.compile(FRAME_PATTERN + re.escape(ext))
    found = pattern.findall(filename)

    return found.pop() if found else None

get_marker_from_clip_index(otio_timeline, clip_index)

Return the clip and marker data from clip index.

Parameters:

Name Type Description Default
otio_timeline dict

otio timeline

required
clip_index str

The clip index.

required

Returns:

Name Type Description
dict

otio clip object

Source code in client/ayon_flame/otio/utils.py
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
def get_marker_from_clip_index(otio_timeline, clip_index):
    """
    Return the clip and marker data from clip index.

    Args:
        otio_timeline (dict): otio timeline
        clip_index (str): The clip index.

    Returns:
        dict: otio clip object

    """
    import ayon_flame.api as ayfapi

    for otio_clip in otio_timeline.find_clips():

        # Retrieve otioClip from parent context otioTimeline
        # See collect_current_project
        for marker in otio_clip.markers:

            if ayfapi.MARKER_NAME not in marker.name:
                continue

            if marker.metadata.get("clip_index") == clip_index:
                return otio_clip, marker

    return None, None

get_padding_from_filename(filename)

Return padding number from Flame path style

Parameters:

Name Type Description Default
filename str

file name

required

Returns:

Name Type Description
int

padding number

Example

get_padding_from_filename("plate.0001.exr") > 4

Source code in client/ayon_flame/otio/utils.py
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
def get_padding_from_filename(filename):
    """
    Return padding number from Flame path style

    Args:
        filename (str): file name

    Returns:
        int: padding number

    Example:
        get_padding_from_filename("plate.0001.exr") > 4

    """
    found = get_frame_from_filename(filename)

    return len(found) if found else None

get_reformatted_filename(filename, padded=True)

Return fixed python expression path

Parameters:

Name Type Description Default
filename str

file name

required

Returns:

Name Type Description
type

string with reformatted path

Example

get_reformatted_filename("plate.1001.exr") > plate.%04d.exr

Source code in client/ayon_flame/otio/utils.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
def get_reformatted_filename(filename, padded=True):
    """
    Return fixed python expression path

    Args:
        filename (str): file name

    Returns:
        type: string with reformatted path

    Example:
        get_reformatted_filename("plate.1001.exr") > plate.%04d.exr

    """
    found = FRAME_PATTERN.search(filename)

    if not found:
        log.info("File name is not sequence: {}".format(filename))
        return filename

    padding = get_padding_from_filename(filename)

    replacement = "%0{}d".format(padding) if padded else "%d"
    start_idx, end_idx = found.span(1)

    return replacement.join(
        [filename[:start_idx], filename[end_idx:]]
    )