# Misc
# AddUsdAttributeToNode
def AddUsdAttributeToNode(nodeName, attrName, typeName, value):
"""Adds a new Usd attribute to the node with the given name.
Args:
nodeName: The name of the node for which to add the Usd attribute.
attrName: The name of the attribute to be added.
typeName: The type of the attribute to be added, specified as a
`UsdAttributeType`.
value: The value of the attribute to be added.
Returns:
The index of the newly added attribute in the list of Usd attributes.
Raises:
ValueError: If an attribute with the given name already exists on
the node or an invalid type name is given.
"""
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Example usage:
import multiverse as mv
# Create a simple Maya object.
cubeXform, _ = cmds.polyCube()
cubeShape = cmds.listRelatives(cubeXform, shapes=True)[0]
# Add the 'displayColor' primvar on the cube's shape node.
mv.AddUsdAttributeToNode(
cubeShape,
'primvars:displayColor',
mv.UsdAttributeType.COLOR,
(0.5, 0.2, 0.1))
# Write the object to a USD file.
filePath = '/tmp/my_cube.usda'
opts = mv.AssetWriteOptions()
opts.writeMeshes = True
opts.writeUsdAttributes = True
mv.WriteAsset(filePath, cubeXform, opts)
# Load the USD file back.
compoundShape = mv.CreateUsdCompound(filePath)
# Add an attributes override.
mvSetNode = cmds.createNode('mvSet')
mv.AddAttributeSetOverride(compoundShape, '/pCubeShape1', mvSetNode)
# Add a custom USD attribute into the 'mvSet'.
mv.AddUsdAttributeToNode(
mvSetNode,
'myFloatAttr',
mv.UsdAttributeType.FLOAT,
123.456)
# Finally write the override with the new custom attribute.
opts = mv.OverridesWriteOptions()
opts.writeAll = True
mv.WriteOverrides('/tmp/my_cube_overrides.usda', compoundShape, opts)
1
2
3
4
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
2
3
4
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
# RemoveUsdAttributeFromNode
def RemoveUsdAttributeFromNode(nodeName, attrName):
"""Removes the Usd attribute with the given name from the given node.
Args:
nodeName: The name of the node for which to remove the Usd attribute.
attrName: The name of the Usd attribute to remove.
Raises:
ValueError: If no attribute with the given name exists on the
node.
"""
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
# GetExistingUsdAttributeNames
def GetExistingUsdAttributeNames(nodeName):
"""Queries the names of the existing USD attributes for the given node.
Args:
nodeName: The name of the node for which to query the names of the
existing USD attributes.
Returns:
A `set` of `str` containing the names of the existing USD attributes
for the given node.
"""
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
# UsdAttributeType
class UsdAttributeType(object):
"""Type of Usd attributes to be added to a node.
Valid constants:
INT
FLOAT
TOKEN
STRING
BOOL
"""
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
# RefreshMEOWPanel
def RefreshMEOWPanel():
"""Refreshes the content of the MEOW panel.
This function does not have any effect in batch/script mode.
"""
1
2
3
4
5
2
3
4
5
← Variants