Skip to content

convert_legacy

Converter for legacy Houdini products.

BlenderLegacyConvertor

Bases: ProductConvertorPlugin

Find and convert any legacy products in the scene.

This Converter will find all legacy products in the scene and will transform them to the current system. Since the old products doesn't retain any information about their original creators, the only mapping we can do is based on their product types.

Its limitation is that you can have multiple creators creating product of the same product type and there is no way to handle it. This code should nevertheless cover all creators that came with OpenPype.

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

    This Converter will find all legacy products in the scene and will
    transform them to the current system. Since the old products doesn't
    retain any information about their original creators, the only mapping
    we can do is based on their product types.

    Its limitation is that you can have multiple creators creating product
    of the same product type and there is no way to handle it. This code
    should nevertheless cover all creators that came with OpenPype.

    """
    identifier = "io.openpype.creators.blender.legacy"
    product_type_to_id = {
        "action": "io.openpype.creators.blender.action",
        "camera": "io.openpype.creators.blender.camera",
        "animation": "io.openpype.creators.blender.animation",
        "blendScene": "io.openpype.creators.blender.blendscene",
        "layout": "io.openpype.creators.blender.layout",
        "model": "io.openpype.creators.blender.model",
        "pointcache": "io.openpype.creators.blender.pointcache",
        "render": "io.openpype.creators.blender.render",
        "review": "io.openpype.creators.blender.review",
        "rig": "io.openpype.creators.blender.rig",
    }

    def __init__(self, *args, **kwargs):
        super(BlenderLegacyConvertor, 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:`~BlenderCreator.cache_instance_data()`

        """
        self.legacy_instances = self.collection_shared_data.get(
            "blender_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 product_type, instance_nodes in self.legacy_instances.items():
            if product_type in self.product_type_to_id:
                for instance_node in instance_nodes:
                    creator_identifier = self.product_type_to_id[product_type]
                    self.log.info(
                        "Converting {} to {}".format(instance_node.name,
                                                     creator_identifier)
                    )
                    imprint(instance_node, data={
                        "creator_identifier": creator_identifier
                    })

convert()

Convert all legacy products to current.

It is enough to add creator_identifier and instance_node.

Source code in client/ayon_blender/plugins/create/convert_legacy.py
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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 product_type, instance_nodes in self.legacy_instances.items():
        if product_type in self.product_type_to_id:
            for instance_node in instance_nodes:
                creator_identifier = self.product_type_to_id[product_type]
                self.log.info(
                    "Converting {} to {}".format(instance_node.name,
                                                 creator_identifier)
                )
                imprint(instance_node, data={
                    "creator_identifier": creator_identifier
                })

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:~BlenderCreator.cache_instance_data()

Source code in client/ayon_blender/plugins/create/convert_legacy.py
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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:`~BlenderCreator.cache_instance_data()`

    """
    self.legacy_instances = self.collection_shared_data.get(
        "blender_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 ""
        )
    )