Skip to content

convert_legacy

Converter for legacy Max products.

MaxLegacyConvertor

Bases: ProductConvertorPlugin

Find and convert any legacy products in the scene.

This Converter will find all creator ids in the scene and will transform them to new creator ids.

Source code in client/ayon_max/plugins/create/convert_legacy.py
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
class MaxLegacyConvertor(ProductConvertorPlugin):
    """Find and convert any legacy products in the scene.

    This Converter will find all creator ids in the scene and will
    transform them to new creator ids.

    """
    identifier = "io.ayon.creators.max.legacy"
    product_type_to_id = {
        "io.openpype.creators.max.camera": "io.ayon.creators.max.camera",
        "io.openpype.creators.max.maxScene": "io.ayon.creators.max.maxScene",
        "io.openpype.creators.max.model": "io.ayon.creators.max.model",
        "io.openpype.creators.max.pointcache": "io.ayon.creators.max.pointcache",
        "io.openpype.creators.max.pointcloud": "io.ayon.creators.max.pointcloud",
        "io.openpype.creators.max.redshiftproxy": "io.ayon.creators.max.redshiftproxy",
        "io.openpype.creators.max.render": "io.ayon.creators.max.render",
        "io.openpype.creators.max.review": "io.ayon.creators.max.review",
        "io.openpype.creators.max.tyflow": "io.ayon.creators.max.tyflow",
        "io.openpype.creators.max.workfile": "io.ayon.creators.max.workfile",
    }

    def __init__(self, *args, **kwargs):
        super(MaxLegacyConvertor, self).__init__(*args, **kwargs)
        self.legacy_instances = {}

    def find_instances(self):
        """Find legacy products in the scene.

        Legacy products are the ones that doesn't have `creator_identifier`
        parameter on them.

        This is using cached entries done in
        :py:meth:`~MaxCreator.cache_instance_data()`

        """
        self.legacy_instances = self.collection_shared_data.get(
            "max_cached_legacy_instances")
        if not self.legacy_instances:
            return
        self.add_convertor_item(
            "Found {} incompatible product{}".format(
                len(self.legacy_instances),
                "s" if len(self.legacy_instances) > 1 else ""
            )
        )

    def convert(self):
        """Convert all legacy products to current.

        It is enough to add `creator_identifier` and `instance_node`.

        """
        if not self.legacy_instances:
            return

        for old_creator_id, instance_nodes in self.legacy_instances.items():
            if old_creator_id in self.product_type_to_id:
                for instance_node in instance_nodes:
                    new_creator_id = self.product_type_to_id[old_creator_id]
                    self.log.info(
                        "Converting {} to {}".format(instance_node,
                                                     new_creator_id)
                    )
                    imprint(instance_node, data={
                        "creator_identifier": new_creator_id
                    })

convert()

Convert all legacy products to current.

It is enough to add creator_identifier and instance_node.

Source code in client/ayon_max/plugins/create/convert_legacy.py
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
def convert(self):
    """Convert all legacy products to current.

    It is enough to add `creator_identifier` and `instance_node`.

    """
    if not self.legacy_instances:
        return

    for old_creator_id, instance_nodes in self.legacy_instances.items():
        if old_creator_id in self.product_type_to_id:
            for instance_node in instance_nodes:
                new_creator_id = self.product_type_to_id[old_creator_id]
                self.log.info(
                    "Converting {} to {}".format(instance_node,
                                                 new_creator_id)
                )
                imprint(instance_node, data={
                    "creator_identifier": new_creator_id
                })

find_instances()

Find legacy products in the scene.

Legacy products are the ones that doesn't have creator_identifier parameter on them.

This is using cached entries done in :py:meth:~MaxCreator.cache_instance_data()

Source code in client/ayon_max/plugins/create/convert_legacy.py
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
def find_instances(self):
    """Find legacy products in the scene.

    Legacy products are the ones that doesn't have `creator_identifier`
    parameter on them.

    This is using cached entries done in
    :py:meth:`~MaxCreator.cache_instance_data()`

    """
    self.legacy_instances = self.collection_shared_data.get(
        "max_cached_legacy_instances")
    if not self.legacy_instances:
        return
    self.add_convertor_item(
        "Found {} incompatible product{}".format(
            len(self.legacy_instances),
            "s" if len(self.legacy_instances) > 1 else ""
        )
    )