ayon-core/pype/plugins/harmony/publish/collect_instances.py
Toke Stuart Jepsen 4fe2ee7bb8 Ftrack and review.
2020-05-27 12:58:15 +01:00

56 lines
1.6 KiB
Python

import json
import pyblish.api
from avalon import harmony
class CollectInstances(pyblish.api.ContextPlugin):
"""Gather instances by nodes metadata.
This collector takes into account assets that are associated with
a composite node and marked with a unique identifier;
Identifier:
id (str): "pyblish.avalon.instance"
"""
label = "Instances"
order = pyblish.api.CollectorOrder
hosts = ["harmony"]
families_mapping = {
"render": ["imagesequence", "review"],
"harmony.template": []
}
def process(self, context):
nodes = harmony.send(
{"function": "node.subNodes", "args": ["Top"]}
)["result"]
for node in nodes:
data = harmony.read(node)
# Skip non-tagged nodes.
if not data:
continue
# Skip containers.
if "container" in data["id"]:
continue
instance = context.create_instance(node.split("/")[-1])
instance.append(node)
instance.data.update(data)
instance.data["publish"] = harmony.send(
{"function": "node.getEnable", "args": [node]}
)["result"]
instance.data["families"] = self.families_mapping[data["family"]]
instance.data["families"].append("ftrack")
# Produce diagnostic message for any graphical
# user interface interested in visualising it.
self.log.info(
"Found: \"{0}\": \n{1}".format(
instance.data["name"], json.dumps(instance.data, indent=4)
)
)