Skip to content

plugin

Plugin API for Mocha Pro AYON addon.

MochaCreator

Bases: Creator

Mocha Pro creator.

Source code in client/ayon_mocha/api/plugin.py
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
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
class MochaCreator(Creator):
    """Mocha Pro creator."""
    def create(self,
               product_name: str,
               instance_data: dict,
               pre_create_data: dict) -> CreatedInstance:
        """Create product instance in the host application.

        Args:
            product_name (str): Name of the product to be created.
            instance_data (dict): Data to be used for creating the product.
            pre_create_data (dict): Data to be used before
                creating the product.

        Returns:
            CreatedInstance: Created product instance.

        """
        instance = CreatedInstance(
            self.product_type,
            product_name,
            instance_data,
            self,
        )
        self._add_instance_to_context(instance)
        host: MochaProHost = self.host
        host.add_publish_instance(instance.data_to_store())\

        return instance

    def collect_instances(self) -> None:
        """Collect instances from the host application."""
        host: MochaProHost = self.host
        for instance_data in host.get_publish_instances():
            if instance_data["creator_identifier"] != self.identifier:
                continue
            created_instance = CreatedInstance.from_existing(
                instance_data, self
            )
            self._add_instance_to_context(created_instance)

    def update_instances(self, update_list: list[dict]) -> None:
        """Update instances in the host application.

        Args:
            update_list (list[dict]): List of instances to be updated.

        """
        host: MochaProHost = self.host
        concurrent_instances = host.get_publish_instances()
        instances_by_id = {
            i_data["instance_id"]: i_data
            for i_data in concurrent_instances
            if i_data["instance_id"]
        }

        instance: CreatedInstance
        for instance, _changes in update_list:
            cur_instance_data = instances_by_id.get(
                instance.data["instance_id"])
            new_data = instance.data_to_store()
            if cur_instance_data is None:
                concurrent_instances.append(instance.data_to_store())
                continue
            for key in set(cur_instance_data) - set(new_data):
                cur_instance_data.pop(key)
            cur_instance_data.update(new_data)
        host.write_create_instances(concurrent_instances)

    def remove_instances(self, instances: list[CreatedInstance]) -> None:
        """Remove instances from the host application.

        Args:
            instances (list[CreatedInstance]): List of instances to be removed.

        """
        host: MochaProHost = self.host
        for instance in instances:
            self._remove_instance_from_context(instance)
            host.remove_create_instance(instance.id)

collect_instances()

Collect instances from the host application.

Source code in client/ayon_mocha/api/plugin.py
46
47
48
49
50
51
52
53
54
55
def collect_instances(self) -> None:
    """Collect instances from the host application."""
    host: MochaProHost = self.host
    for instance_data in host.get_publish_instances():
        if instance_data["creator_identifier"] != self.identifier:
            continue
        created_instance = CreatedInstance.from_existing(
            instance_data, self
        )
        self._add_instance_to_context(created_instance)

create(product_name, instance_data, pre_create_data)

Create product instance in the host application.

Parameters:

Name Type Description Default
product_name str

Name of the product to be created.

required
instance_data dict

Data to be used for creating the product.

required
pre_create_data dict

Data to be used before creating the product.

required

Returns:

Name Type Description
CreatedInstance CreatedInstance

Created product instance.

Source code in client/ayon_mocha/api/plugin.py
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
def create(self,
           product_name: str,
           instance_data: dict,
           pre_create_data: dict) -> CreatedInstance:
    """Create product instance in the host application.

    Args:
        product_name (str): Name of the product to be created.
        instance_data (dict): Data to be used for creating the product.
        pre_create_data (dict): Data to be used before
            creating the product.

    Returns:
        CreatedInstance: Created product instance.

    """
    instance = CreatedInstance(
        self.product_type,
        product_name,
        instance_data,
        self,
    )
    self._add_instance_to_context(instance)
    host: MochaProHost = self.host
    host.add_publish_instance(instance.data_to_store())\

    return instance

remove_instances(instances)

Remove instances from the host application.

Parameters:

Name Type Description Default
instances list[CreatedInstance]

List of instances to be removed.

required
Source code in client/ayon_mocha/api/plugin.py
85
86
87
88
89
90
91
92
93
94
95
def remove_instances(self, instances: list[CreatedInstance]) -> None:
    """Remove instances from the host application.

    Args:
        instances (list[CreatedInstance]): List of instances to be removed.

    """
    host: MochaProHost = self.host
    for instance in instances:
        self._remove_instance_from_context(instance)
        host.remove_create_instance(instance.id)

update_instances(update_list)

Update instances in the host application.

Parameters:

Name Type Description Default
update_list list[dict]

List of instances to be updated.

required
Source code in client/ayon_mocha/api/plugin.py
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
def update_instances(self, update_list: list[dict]) -> None:
    """Update instances in the host application.

    Args:
        update_list (list[dict]): List of instances to be updated.

    """
    host: MochaProHost = self.host
    concurrent_instances = host.get_publish_instances()
    instances_by_id = {
        i_data["instance_id"]: i_data
        for i_data in concurrent_instances
        if i_data["instance_id"]
    }

    instance: CreatedInstance
    for instance, _changes in update_list:
        cur_instance_data = instances_by_id.get(
            instance.data["instance_id"])
        new_data = instance.data_to_store()
        if cur_instance_data is None:
            concurrent_instances.append(instance.data_to_store())
            continue
        for key in set(cur_instance_data) - set(new_data):
            cur_instance_data.pop(key)
        cur_instance_data.update(new_data)
    host.write_create_instances(concurrent_instances)

MochaLoader

Bases: LoaderPlugin

Mocha Pro loader base class.

Source code in client/ayon_mocha/api/plugin.py
 98
 99
100
101
class MochaLoader(load.LoaderPlugin):
    """Mocha Pro loader base class."""
    settings_category = "mochapro"
    hosts: ClassVar[list[str]] = ["mochapro"]