Skip to content

integrate_animation

IntegrateAnimation

Bases: BlenderInstancePlugin, OptionalPyblishPluginMixin

Generate a JSON file for animation.

Source code in client/ayon_blender/plugins/publish/integrate_animation.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
class IntegrateAnimation(
    plugin.BlenderInstancePlugin,
    OptionalPyblishPluginMixin,
):
    """Generate a JSON file for animation."""

    label = "Integrate Animation"
    order = pyblish.api.IntegratorOrder + 0.1
    optional = True
    hosts = ["blender"]
    families = ["setdress"]

    def process(self, instance):
        self.log.debug("Integrate Animation")

        representation = instance.data.get('representations')[0]
        json_path = representation.get('publishedFiles')[0]

        with open(json_path, "r") as file:
            data = json.load(file)

        # Update the json file for the setdress to add the published
        # representations of the animations
        for json_dict in data:
            json_product_name = json_dict["productName"]
            i = None
            for elem in instance.context:
                if elem.data["productName"] == json_product_name:
                    i = elem
                    break
            if not i:
                continue
            rep = None
            pub_repr = i.data["published_representations"]
            for elem in pub_repr:
                if pub_repr[elem]["representation"]["name"] == "fbx":
                    rep = pub_repr[elem]
                    break
            if not rep:
                continue
            obj_id = rep["representation"]["id"]

            if obj_id:
                json_dict["representation_id"] = str(obj_id)

        with open(json_path, "w") as file:
            json.dump(data, fp=file, indent=2)