Skip to content

create_maya_usd_layer

CreateMayaUsdLayer

Bases: MayaCreator

Create Maya USD Export from mayaUsdProxyShape layer

Source code in client/ayon_maya/plugins/create/create_maya_usd_layer.py
 5
 6
 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
class CreateMayaUsdLayer(plugin.MayaCreator):
    """Create Maya USD Export from `mayaUsdProxyShape` layer"""

    identifier = "io.openpype.creators.maya.mayausdlayer"
    label = "Maya USD Export Layer"
    product_type = "usd"
    icon = "cubes"
    description = "Create mayaUsdProxyShape layer export"

    def get_publish_families(self):
        return ["usd", "mayaUsdLayer"]

    def get_instance_attr_defs(self):

        from maya import cmds
        import mayaUsd

        # Construct the stage + layer EnumDef from the maya proxies in the
        # scene and the Sdf.Layer stack of the Usd.Stage per proxy.
        items = []
        for proxy in cmds.ls(type="mayaUsdProxyShape", long=True):
            stage = mayaUsd.ufe.getStage("|world{}".format(proxy))
            if not stage:
                continue

            for layer in stage.GetLayerStack(includeSessionLayers=False):

                proxy_nice_name = proxy.rsplit("|", 2)[-2]
                layer_nice_name = layer.GetDisplayName()
                label = "{} -> {}".format(proxy_nice_name, layer_nice_name)
                value = ">".join([proxy, layer.identifier])

                items.append({
                    "label": label,
                    "value": value
                })

        if not items:
            # EnumDef is not allowed to be empty
            items.append("<NONE>")

        defs = [
            EnumDef("defaultUSDFormat",
                    label="File format",
                    items={
                        "usdc": "Binary",
                        "usda": "ASCII"
                    },
                    default="usdc"),
            EnumDef("stageLayerIdentifier",
                    label="Stage and Layer Identifier",
                    items=items)
        ]

        return defs