Skip to content

load_usd_reference

USDReferenceLoader

Bases: HoudiniLoader

Reference USD file in Solaris

Source code in client/ayon_houdini/plugins/load/load_usd_reference.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
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
class USDReferenceLoader(plugin.HoudiniLoader):
    """Reference USD file in Solaris"""

    product_base_types = {
        "usd",
        "usdCamera",
    }
    product_types = product_base_types
    label = "Reference USD"
    representations = {"*"}
    extensions = {"usd", "usda", "usdlc", "usdnc", "abc"}
    order = -8

    icon = "code-fork"
    color = "orange"

    use_ayon_entity_uri = False

    def load(self, context, name=None, namespace=None, data=None):

        # Format file name, Houdini only wants forward slashes
        file_path = self.filepath_from_context(context)
        file_path = file_path.replace("\\", "/")

        # Get the root node
        stage = hou.node("/stage")

        # Define node name
        namespace = namespace if namespace else context["folder"]["name"]
        node_name = "{}_{}".format(namespace, name) if namespace else name

        # Create USD reference
        container = stage.createNode("reference", node_name=node_name)
        container.setParms({"filepath1": file_path})
        container.moveToGoodPosition()

        # Imprint it manually
        data = {
            "schema": "ayon:container-3.0",
            "id": AYON_CONTAINER_ID,
            "name": node_name,
            "namespace": namespace,
            "loader": str(self.__class__.__name__),
            "representation": context["representation"]["id"],
        }

        # todo: add folder="AYON"
        lib.imprint(container, data)

        return container

    def update(self, container, context):
        node = container["node"]

        # Update the file path
        file_path = self.filepath_from_context(context)
        file_path = file_path.replace("\\", "/")

        # Update attributes
        node.setParms(
            {
                "filepath1": file_path,
                "representation": context["representation"]["id"],
            }
        )

        # Reload files
        node.parm("reload").pressButton()

    def remove(self, container):

        node = container["node"]
        node.destroy()

    def switch(self, container, context):
        self.update(container, context)

    def create_load_placeholder_node(
        self, node_name: str, placeholder_data: dict
    ) -> hou.Node:
        """Define how to create a placeholder node for this loader for the
        Workfile Template Builder system."""
        # Create node
        network = lib.find_active_network(
            category=hou.lopNodeTypeCategory(),
            default="/stage"
        )
        node = network.createNode("null", node_name=node_name)
        node.moveToGoodPosition()
        return node

create_load_placeholder_node(node_name, placeholder_data)

Define how to create a placeholder node for this loader for the Workfile Template Builder system.

Source code in client/ayon_houdini/plugins/load/load_usd_reference.py
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
def create_load_placeholder_node(
    self, node_name: str, placeholder_data: dict
) -> hou.Node:
    """Define how to create a placeholder node for this loader for the
    Workfile Template Builder system."""
    # Create node
    network = lib.find_active_network(
        category=hou.lopNodeTypeCategory(),
        default="/stage"
    )
    node = network.createNode("null", node_name=node_name)
    node.moveToGoodPosition()
    return node