Skip to content

render_utils

export_clip(export_path, clip, preset_path, **kwargs)

Flame exported wrapper

Parameters:

Name Type Description Default
export_path str

exporting directory path

required
clip PyClip

flame api object

required
preset_path str

full export path to xml file

required
Kwargs

thumb_frame_number (int)[optional]: source frame number in_mark (int)[optional]: cut in mark out_mark (int)[optional]: cut out mark

Raises:

Type Description
KeyError

Missing input kwarg thumb_frame_number in case thumbnail in export_preset

FileExistsError

Missing export preset in shared folder

Source code in client/ayon_flame/api/render_utils.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
57
58
59
60
61
62
63
64
def export_clip(export_path, clip, preset_path, **kwargs):
    """Flame exported wrapper

    Args:
        export_path (str): exporting directory path
        clip (PyClip): flame api object
        preset_path (str): full export path to xml file

    Kwargs:
        thumb_frame_number (int)[optional]: source frame number
        in_mark (int)[optional]: cut in mark
        out_mark (int)[optional]: cut out mark

    Raises:
        KeyError: Missing input kwarg `thumb_frame_number`
                  in case `thumbnail` in `export_preset`
        FileExistsError: Missing export preset in shared folder
    """
    import flame

    in_mark = out_mark = None

    # Set exporter
    exporter = flame.PyExporter()
    exporter.foreground = True
    exporter.export_between_marks = True

    if kwargs.get("thumb_frame_number"):
        thumb_frame_number = kwargs["thumb_frame_number"]
        # make sure it exists in kwargs
        if not thumb_frame_number:
            raise KeyError(
                "Missing key `thumb_frame_number` in input kwargs")

        in_mark = int(thumb_frame_number)
        out_mark = int(thumb_frame_number) + 1

    elif kwargs.get("in_mark") and kwargs.get("out_mark"):
        in_mark = int(kwargs["in_mark"])
        out_mark = int(kwargs["out_mark"])
    else:
        exporter.export_between_marks = False

    try:
        # set in and out marks if they are available
        if in_mark and out_mark:
            clip.in_mark = in_mark
            clip.out_mark = out_mark

        # export with exporter
        exporter.export(clip, preset_path, export_path)
    finally:
        print('Exported: {} at {}-{}'.format(
            clip.name.get_value(),
            clip.in_mark,
            clip.out_mark
        ))

modify_preset_file(xml_path, staging_dir, data)

Modify xml preset with input data

Parameters:

Name Type Description Default
xml_path str

path for input xml preset

required
staging_dir str

staging dir path

required
data dict

data where key is xmlTag and value as string

required

Returns:

Name Type Description
str

description

Source code in client/ayon_flame/api/render_utils.py
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
def modify_preset_file(xml_path, staging_dir, data):
    """Modify xml preset with input data

    Args:
        xml_path (str ): path for input xml preset
        staging_dir (str): staging dir path
        data (dict): data where key is xmlTag and value as string

    Returns:
        str: _description_
    """
    # create temp path
    dirname, basename = os.path.split(xml_path)
    temp_path = os.path.join(staging_dir, basename)

    # change xml following data keys
    with open(xml_path, "r") as datafile:
        _root = ET.parse(datafile)

        for key, value in data.items():
            try:
                if "/" in key:
                    if not key.startswith("./"):
                        key = ".//" + key

                    split_key_path = key.split("/")
                    element_key = split_key_path[-1]
                    parent_obj_path = "/".join(split_key_path[:-1])

                    parent_obj = _root.find(parent_obj_path)
                    element_obj = parent_obj.find(element_key)
                    if not element_obj:
                        append_element(parent_obj, element_key, value)
                else:
                    finds = _root.findall(".//{}".format(key))
                    if not finds:
                        raise AttributeError
                    for element in finds:
                        element.text = str(value)
            except AttributeError:
                log.warning(
                    "Cannot create attribute: {}: {}. Skipping".format(
                        key, value
                    ))
        _root.write(temp_path)

    return temp_path