Skip to content

load_matlib

LoadMatlib

Bases: LoaderPlugin

Load material library files with Material Library

Source code in client/ayon_max/plugins/load/load_matlib.py
 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
class LoadMatlib(load.LoaderPlugin):
    """Load material library files with Material Library"""

    label = "Load Material Library"
    product_base_types = {"matlib"}
    product_types = product_base_types
    representations = {"*"}
    extensions = {"mat"}
    order = -9
    icon = "code-fork"
    color = "white"

    def load(self, context, name, namespace, data):
        """Load the material library file into the scene and containerise it."""
        file_path = self.filepath_from_context(context)
        folder_name = context["folder"]["name"]
        namespace = unique_namespace(
            name + "_",
            prefix=f"{folder_name}_",
            suffix="_",
        )
        rt.sme.OpenMtlLib(file_path)
        return containerise(
            name,
            [],
            context,
            namespace=namespace,
            loader=self.__class__.__name__,
            additional_data={"matlib_filepath": file_path}
        )

    def remove(self, container):
        """Remove the material library from the scene and clean up the container."""
        matlib_filepath = container["matlib_filepath"]
        if matlib_filepath:
            rt.sme.CloseMtlLib(matlib_filepath)
        container_node = rt.getNodeByName(container["instance_node"])
        remove_container_data(container_node)

load(context, name, namespace, data)

Load the material library file into the scene and containerise it.

Source code in client/ayon_max/plugins/load/load_matlib.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
def load(self, context, name, namespace, data):
    """Load the material library file into the scene and containerise it."""
    file_path = self.filepath_from_context(context)
    folder_name = context["folder"]["name"]
    namespace = unique_namespace(
        name + "_",
        prefix=f"{folder_name}_",
        suffix="_",
    )
    rt.sme.OpenMtlLib(file_path)
    return containerise(
        name,
        [],
        context,
        namespace=namespace,
        loader=self.__class__.__name__,
        additional_data={"matlib_filepath": file_path}
    )

remove(container)

Remove the material library from the scene and clean up the container.

Source code in client/ayon_max/plugins/load/load_matlib.py
40
41
42
43
44
45
46
def remove(self, container):
    """Remove the material library from the scene and clean up the container."""
    matlib_filepath = container["matlib_filepath"]
    if matlib_filepath:
        rt.sme.CloseMtlLib(matlib_filepath)
    container_node = rt.getNodeByName(container["instance_node"])
    remove_container_data(container_node)