Skip to content

load_file

FileLoader

Bases: AfterEffectsLoader

Load images

Stores the imported product version in a container named after the folder.

Source code in client/ayon_aftereffects/plugins/load/load_file.py
  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
 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
class FileLoader(api.AfterEffectsLoader):
    """Load images

    Stores the imported product version in a container named after the folder.
    """
    label = "Load file"

    product_types = {
        "image",
        "plate",
        "render",
        "prerender",
        "review",
        "audio",
    }
    representations = {"*"}

    def load(self, context, name=None, namespace=None, data=None):
        stub = self.get_stub()
        loaded_item_name = f"{context['folder']['name']}_{name}"
        footages = stub.get_items(comps=False, footages=True, folders=False)
        loaded_item_name = self._get_unique_loaded_item_name(
            stub, footages, loaded_item_name
        )

        import_options = {}

        path = self.filepath_from_context(context)

        if len(context["representation"]["files"]) > 1:
            import_options['sequence'] = True

        if not path:
            repr_id = context["representation"]["id"]
            self.log.warning(
                f"Representation id `{repr_id}` is failing to load"
            )
            return

        path = path.replace("\\", "/")
        if '.psd' in path:
            import_options['ImportAsType'] = 'ImportAsType.COMP'

        loaded_item = stub.import_file(
            path, stub.LOADED_ICON + loaded_item_name, import_options
        )
        if not loaded_item:
            self.log.warning(
                f"Representation `{path}` is failing to load"
            )
            self.log.warning("Check host app for alert error.")
            return

        self[:] = [loaded_item]
        namespace = namespace or loaded_item_name
        return api.containerise(
            name,
            namespace,
            loaded_item,
            context,
            self.__class__.__name__
        )

    def update(self, container, context):
        stub = self.get_stub()
        item = container.pop("layer")

        folder_name = context["folder"]["name"]
        product_name = context["product"]["name"]
        repre_entity = context["representation"]

        namespace_from_container = re.sub(
            r"_\d{3}$", "", container["namespace"]
        )

        loaded_item_name = f"{folder_name}_{product_name}"
        if namespace_from_container != loaded_item_name:
            footages = stub.get_items(
                comps=False, footages=True, folders=False
            )
            loaded_item_name = self._get_unique_loaded_item_name(
                stub, footages, loaded_item_name
            )
        else:  # switching version - keep same name
            loaded_item_name = container["namespace"]
        path = get_representation_path(repre_entity)

        if len(repre_entity["files"]) > 1:
           path = os.path.dirname(path)
        stub.replace_item(item.id, path, stub.LOADED_ICON + loaded_item_name)
        stub.imprint(
            item.id,
            {
                "representation": repre_entity["id"],
                "name": product_name,
                "namespace": loaded_item_name
            }
        )