Skip to content

plugin

Motion Builder specific AYON/Pyblish plugin definitions.

MotionBuilderCreator

Bases: Creator, MotionBuilderCreatorBase

Source code in client/ayon_motionbuilder/api/plugin.py
 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
class MotionBuilderCreator(Creator, MotionBuilderCreatorBase):

    def create(self, product_name, instance_data, pre_create_data):
        creator_attributes = instance_data.setdefault(
            "creator_attributes", {})
        for key in [
            "EmbedMedia",
            "SaveSelectedModelsOnly",
            "KeepTransformHierarchy",
        ]:
            if key in pre_create_data:
                creator_attributes[key] = pre_create_data[key]
        instance_node = self.create_node(product_name)
        instance_data["instance_node"] = instance_node
        # TODO: supports to select models to be published
        if pre_create_data.get("SaveSelectedModelsOnly"):
            instance_data["selected_nodes"] = [
                sel.Name for sel in get_selection()
            ]
            node = get_node_by_name(instance_node)
            if node:
                for sel in get_selection():
                    node.ConnectSrc(sel)

        instance = CreatedInstance(
            self.product_type,
            product_name,
            instance_data,
            self
        )
        self._add_instance_to_context(instance)
        instances_imprint(instance_node, instance.data_to_store())
        return instance

    def collect_instances(self):
        self.cache_instance_data(self.collection_shared_data)
        cached_instances = (
            self.collection_shared_data["mbuilder_cached_instances"]
        )
        for instance in cached_instances.get(self.identifier, []):
            created_instance = CreatedInstance.from_existing(
                read(get_node_by_name(instance)), self
            )
            self._add_instance_to_context(created_instance)

    def update_instances(self, update_list):
        for created_inst, changes in update_list:
            instance_node = created_inst.get("instance_node")
            new_values = {
                key: changes[key].new_value
                for key in changes.changed_keys
            }
            product_name = new_values.get("productName", "")
            if product_name and instance_node != product_name:
                new_product_name = new_values["productName"]
                node = get_node_by_name(instance_node)
                instance_node = new_product_name
                created_inst["instance_node"] = instance_node
                node.Name = instance_node

            instances_imprint(
                instance_node,
                created_inst.data_to_store()
            )

    def remove_instances(self, instances):
        """Remove specified instance from the scene.

        This is only removing `id` parameter so instance is no longer
        instance, because it might contain valuable data for artist.

        """
        for instance in instances:
            instance_node = get_node_by_name(
                instance.data.get("instance_node")
            )
            if instance_node:
               instance_node.FBDelete()
            self._remove_instance_from_context(instance)

    def get_instance_attr_defs(self):
        return [
            BoolDef("EmbedMedia",
                    label="Embed Media"),
            BoolDef("SaveSelectedModelsOnly",
                    label="Save Selected Models Only"),
            BoolDef("KeepTransformHierarchy",
                    label="Keep Transform Hierarchy"),
        ]

    def get_pre_create_attr_defs(self):
        return self.get_instance_attr_defs()

remove_instances(instances)

Remove specified instance from the scene.

This is only removing id parameter so instance is no longer instance, because it might contain valuable data for artist.

Source code in client/ayon_motionbuilder/api/plugin.py
114
115
116
117
118
119
120
121
122
123
124
125
126
127
def remove_instances(self, instances):
    """Remove specified instance from the scene.

    This is only removing `id` parameter so instance is no longer
    instance, because it might contain valuable data for artist.

    """
    for instance in instances:
        instance_node = get_node_by_name(
            instance.data.get("instance_node")
        )
        if instance_node:
           instance_node.FBDelete()
        self._remove_instance_from_context(instance)