Skip to content

collect_render

Collect render instances in Harmony.

CollectHarmonyRenderInstances

Bases: AbstractCollectRender

Collect render instances from Harmony.

Create regular render instances based on ones created in the publisher.

Source code in client/ayon_harmony/plugins/publish/collect_render.py
 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
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
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
131
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
class CollectHarmonyRenderInstances(publish.AbstractCollectRender):
    """Collect render instances from Harmony.

    Create regular render instances based on ones created in the publisher.
    """

    label = "Collect Render Instances"
    order = pyblish.api.CollectorOrder + 0.01
    hosts = ["harmony"]
    families = ["render"]

    # https://docs.toonboom.com/help/harmony-17/premium/reference/node/output/write-node-image-formats.html
    ext_mapping = {
        "tvg": ["TVG"],
        "tga": ["TGA", "TGA4", "TGA3", "TGA1"],
        "sgi": ["SGI", "SGI4", "SGA3", "SGA1", "SGIDP", "SGIDP4", "SGIDP3"],
        "psd": [
            "PSD",
            "PSD1",
            "PSD3",
            "PSD4",
            "PSDDP",
            "PSDDP1",
            "PSDDP3",
            "PSDDP4",
        ],
        "yuv": ["YUV"],
        "pal": ["PAL"],
        "scan": ["SCAN"],
        "png": ["PNG", "PNG4", "PNGDP", "PNGDP3", "PNGDP4"],
        "jpg": ["JPG"],
        "bmp": ["BMP", "BMP4"],
        "opt": ["OPT", "OPT1", "OPT3", "OPT4"],
        "var": ["VAR"],
        "tif": ["TIF"],
        "dpx": [
            "DPX",
            "DPX3_8",
            "DPX3_10",
            "DPX3_12",
            "DPX3_16",
            "DPX3_10_INVERTED_CHANNELS",
            "DPX3_12_INVERTED_CHANNELS",
            "DPX3_16_INVERTED_CHANNELS",
        ],
        "exr": ["EXR"],
        "pdf": ["PDF"],
        "dtext": ["DTEX"],
    }

    def get_instances(self, context):
        """Get instances per Write node."""
        version = None
        if self.sync_workfile_version:
            version = context.data["version"]

        folder_path = context.data["folderPath"]
        instances = []

        for instance in context:
            # Check if instance should be processed
            if not self.check_process_instance(instance):
                continue

            # Get creator attributes for render target
            creator_attributes = instance.data.get("creator_attributes", {})
            render_target = creator_attributes.get("render_target", "default")

            node = instance.data["setMembers"][0]
            # 0 - filename / 1 - type / 2 - zeros / 3 - start / 4 - enabled
            info = harmony.send(
                {
                    "function": "AyonHarmony.getRenderNodeSettings",
                    "args": node
                }
            )["result"]

            product_name = instance.data["productName"]
            product_base_type = instance.data["productBaseType"]
            product_type = instance.data["productType"]

            instance_families = instance.data.get("families", [])

            render_instance = HarmonyRenderInstance(
                version=version,
                time=get_formatted_current_time(),
                source=context.data["currentFile"],
                name=product_name,
                label="{} - {}".format(product_name, product_type),
                productName=product_name,
                productBaseType=product_base_type,
                productType=product_type,
                family=product_type,
                families=instance_families,
                folderPath=folder_path,
                task=instance.data.get("task"),
                attachTo=False,
                setMembers=[instance.data["setMembers"][0]],
                publish=True,
                renderer=None,
                priority=50,
                resolutionWidth=context.data["resolutionWidth"],
                resolutionHeight=context.data["resolutionHeight"],
                pixelAspect=1.0,
                multipartExr=False,
                tileRendering=False,
                tilesX=0,
                tilesY=0,
                convertToScanline=False,
                frameStart=instance.data.get(
                    "frameStart", context.data.get("frameStart")
                ),
                frameEnd=instance.data.get(
                    "frameEnd", context.data.get("frameEnd")
                ),
                handleStart=instance.data.get(
                    "handleStart", context.data.get("handleStart")
                ),
                handleEnd=instance.data.get(
                    "handleEnd", context.data.get("handleEnd")
                ),
                frameStep=1,
                review=True,
                farm=(render_target == "farm"),
                ignoreFrameHandleCheck=True,
                source_instance=instance,
                # for farm submission
                outputType="Image",
                outputFormat=info[1],
                outputStartFrame=info[3],
                leadingZeros=info[2],
            )

            if render_instance:
                self.log.debug(f"Creating render instance: {render_instance}")

                instances.append(render_instance)

        return instances

    def check_process_instance(self, instance):
        """Check if instance should be processed.

        Args:
            instance (pyblish.api.Instance): Instance to check

        Returns:
            bool: True if instance should be processed
        """
        if (
            not instance.data.get("active", True)
            or instance.data.get("productType") != "render"
        ):
            return False
        return True

    def get_expected_files(self, render_instance):
        """Get list of expected files to be rendered from Harmony.

        This returns full path with file name determined by Write node
        settings.
        """
        start = render_instance.frameStart - render_instance.handleStart
        end = render_instance.frameEnd + render_instance.handleEnd
        node = render_instance.setMembers[0]

        # 0 - filename / 1 - type / 2 - zeros / 3 - start
        info = harmony.send(
            {"function": "AyonHarmony.getRenderNodeSettings", "args": node}
        )["result"]

        ext = None
        for k, v in self.ext_mapping.items():
            if info[1] in v:
                ext = k

        if not ext:
            raise AssertionError(
                f"Cannot determine file extension for {info[1]}"
            )

        path = Path(render_instance.source).parent
        expected_files = []

        # '-' in name is important for Harmony17
        for frame in range(start, end + 1):
            expected_files.append(
                path
                / "{}-{}.{}".format(
                    render_instance.productName,
                    str(frame).rjust(int(info[2]) + 1, "0"),
                    ext,
                )
            )
        self.log.debug("expected_files::{}".format(expected_files))
        return expected_files

    def add_additional_data(self, instance_data):
        creator_attributes = instance_data.get("creator_attributes", {})
        # Add FOV for farm instances
        if creator_attributes.get("render_target") == "farm":
            instance_data["FOV"] = self._context.data["FOV"]

        return instance_data

check_process_instance(instance)

Check if instance should be processed.

Parameters:

Name Type Description Default
instance Instance

Instance to check

required

Returns:

Name Type Description
bool

True if instance should be processed

Source code in client/ayon_harmony/plugins/publish/collect_render.py
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
def check_process_instance(self, instance):
    """Check if instance should be processed.

    Args:
        instance (pyblish.api.Instance): Instance to check

    Returns:
        bool: True if instance should be processed
    """
    if (
        not instance.data.get("active", True)
        or instance.data.get("productType") != "render"
    ):
        return False
    return True

get_expected_files(render_instance)

Get list of expected files to be rendered from Harmony.

This returns full path with file name determined by Write node settings.

Source code in client/ayon_harmony/plugins/publish/collect_render.py
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
def get_expected_files(self, render_instance):
    """Get list of expected files to be rendered from Harmony.

    This returns full path with file name determined by Write node
    settings.
    """
    start = render_instance.frameStart - render_instance.handleStart
    end = render_instance.frameEnd + render_instance.handleEnd
    node = render_instance.setMembers[0]

    # 0 - filename / 1 - type / 2 - zeros / 3 - start
    info = harmony.send(
        {"function": "AyonHarmony.getRenderNodeSettings", "args": node}
    )["result"]

    ext = None
    for k, v in self.ext_mapping.items():
        if info[1] in v:
            ext = k

    if not ext:
        raise AssertionError(
            f"Cannot determine file extension for {info[1]}"
        )

    path = Path(render_instance.source).parent
    expected_files = []

    # '-' in name is important for Harmony17
    for frame in range(start, end + 1):
        expected_files.append(
            path
            / "{}-{}.{}".format(
                render_instance.productName,
                str(frame).rjust(int(info[2]) + 1, "0"),
                ext,
            )
        )
    self.log.debug("expected_files::{}".format(expected_files))
    return expected_files

get_instances(context)

Get instances per Write node.

Source code in client/ayon_harmony/plugins/publish/collect_render.py
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
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
131
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
def get_instances(self, context):
    """Get instances per Write node."""
    version = None
    if self.sync_workfile_version:
        version = context.data["version"]

    folder_path = context.data["folderPath"]
    instances = []

    for instance in context:
        # Check if instance should be processed
        if not self.check_process_instance(instance):
            continue

        # Get creator attributes for render target
        creator_attributes = instance.data.get("creator_attributes", {})
        render_target = creator_attributes.get("render_target", "default")

        node = instance.data["setMembers"][0]
        # 0 - filename / 1 - type / 2 - zeros / 3 - start / 4 - enabled
        info = harmony.send(
            {
                "function": "AyonHarmony.getRenderNodeSettings",
                "args": node
            }
        )["result"]

        product_name = instance.data["productName"]
        product_base_type = instance.data["productBaseType"]
        product_type = instance.data["productType"]

        instance_families = instance.data.get("families", [])

        render_instance = HarmonyRenderInstance(
            version=version,
            time=get_formatted_current_time(),
            source=context.data["currentFile"],
            name=product_name,
            label="{} - {}".format(product_name, product_type),
            productName=product_name,
            productBaseType=product_base_type,
            productType=product_type,
            family=product_type,
            families=instance_families,
            folderPath=folder_path,
            task=instance.data.get("task"),
            attachTo=False,
            setMembers=[instance.data["setMembers"][0]],
            publish=True,
            renderer=None,
            priority=50,
            resolutionWidth=context.data["resolutionWidth"],
            resolutionHeight=context.data["resolutionHeight"],
            pixelAspect=1.0,
            multipartExr=False,
            tileRendering=False,
            tilesX=0,
            tilesY=0,
            convertToScanline=False,
            frameStart=instance.data.get(
                "frameStart", context.data.get("frameStart")
            ),
            frameEnd=instance.data.get(
                "frameEnd", context.data.get("frameEnd")
            ),
            handleStart=instance.data.get(
                "handleStart", context.data.get("handleStart")
            ),
            handleEnd=instance.data.get(
                "handleEnd", context.data.get("handleEnd")
            ),
            frameStep=1,
            review=True,
            farm=(render_target == "farm"),
            ignoreFrameHandleCheck=True,
            source_instance=instance,
            # for farm submission
            outputType="Image",
            outputFormat=info[1],
            outputStartFrame=info[3],
            leadingZeros=info[2],
        )

        if render_instance:
            self.log.debug(f"Creating render instance: {render_instance}")

            instances.append(render_instance)

    return instances