Skip to content

load_placeholder

Placeholder to trigger loader action during workfile build.

MaxPlaceholderLoadPlugin

Bases: MaxPlaceholderPlugin, PlaceholderLoadMixin

Source code in client/ayon_max/plugins/workfile_build/load_placeholder.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
 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
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
class MaxPlaceholderLoadPlugin(MaxPlaceholderPlugin, PlaceholderLoadMixin):
    identifier = "max.load"
    label = "Max load"

    item_class = LoadPlaceholderItem

    def _create_placeholder_name(self, placeholder_data):

        # Split builder type: context_assets, linked_assets, all_assets
        prefix, suffix = placeholder_data["builder_type"].split("_", 1)
        parts = [prefix]

        product_base_type = placeholder_data.get("product_base_type")
        if not product_base_type:
            product_base_type = placeholder_data.get("product_type")
        if product_base_type:
            parts.append(product_base_type)

        # add loader arguments if any
        loader_args = placeholder_data["loader_args"]
        if loader_args:
            loader_args = eval(loader_args)
            for value in loader_args.values():
                parts.append(str(value))

        parts.append(suffix)
        placeholder_name = "_".join(parts)

        return placeholder_name.capitalize()

    def _get_loaded_repre_ids(self):
        loaded_representation_ids = self.builder.get_shared_populate_data(
            "loaded_representation_ids"
        )
        if loaded_representation_ids is None:
            try:
                containers = get_containers()

            except ValueError:
                containers = []

            container_data = {
                read(container)
                for container in containers
            }
            loaded_representation_ids = {
                data["representation"]
                for data in container_data
            }
            self.builder.set_shared_populate_data(
                "loaded_representation_ids", loaded_representation_ids
            )
        return loaded_representation_ids

    def populate_placeholder(self, placeholder):
        self.populate_load_placeholder(placeholder)
        if not placeholder.data.get("keep_placeholder", True):
            self.delete_placeholder(placeholder)

    def repopulate_placeholder(self, placeholder):
        repre_ids = self._get_loaded_repre_ids()
        self.populate_load_placeholder(placeholder, repre_ids)

    def get_placeholder_options(self, options=None):
        return self.get_load_plugin_options(options)

    def load_succeed(self, placeholder, container):
        self._parent_in_hierarchy(placeholder, container)

    def _parent_in_hierarchy(self, placeholder, container):
        """Parent loaded container to placeholder's parent.

        ie : Set loaded content as placeholder's sibling

        Args:
            container (str): Placeholder loaded container
        """

        if not container:
            return

        loaded_container: Optional[rt.objects] = next(
            (
                target_container
                for target_container in get_containers()
                if container == target_container.name
            ),
            None
        )
        if not loaded_container:
            return

        placeholder_node = rt.getNodeByName(placeholder.scene_identifier)
        if not placeholder_node:
            return
        if rt.isValidNode(loaded_container):
            loaded_container.parent = placeholder_node