Last active
June 3, 2025 14:37
-
-
Save BigRoy/d6ec71e2f2459c085ffbe1cf5fe59fa9 to your computer and use it in GitHub Desktop.
Utility functions to easily set some attributes on Maya nodes for Maya USD Export to use.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Utility functions to easily set some attributes on Maya nodes for Maya USD Export to use. | |
For example, make it easy to set the purpose, type or kind for the resulting USD Prims. | |
See Maya USD - Custom Attributes and Tagging for USD: | |
https://github.com/Autodesk/maya-usd/blob/dev/lib/mayaUsd/commands/Readme.md#custom-attributes-and-tagging-for-usd | |
""" | |
from __future__ import annotations | |
from maya import cmds | |
from typing import Literal, Union | |
def _setattr(node: str, attr: str, value: str): | |
attr_exists = cmds.attributeQuery(attr, node=node, exists=True) | |
plug = f"{node}.{attr}" | |
if value is None: | |
# Delete attribute | |
if attr_exists: | |
cmds.deleteAttr(plug) | |
return | |
if not attr_exists: | |
cmds.addAttr(node, ln=attr, dt="string") | |
cmds.setAttr(plug, value, type="string") | |
def set_usd_purpose(node, value: Literal["default", "render", "proxy", "guide", None]): | |
"""Set USD Purpose.""" | |
_setattr(node, "USD_ATTR_purpose", value) | |
def set_usd_kind(node, value: Union[str, None]): | |
"""Set USD Kind, e.g. 'component', 'assembly', etc.""" | |
_setattr(node, "USD_kind", value) | |
def set_usd_type_name(node, value: Union[str, None]): | |
"""Set USD Type Name, e.g. 'SkelRoot'""" | |
_setattr(node, "USD_typeName", value) | |
def set_usd_subdivision_scheme(node, value: Literal["none", "bilinear", "catmullClark", "loop", None]): | |
"""Set USD Subdivision Scheme for meshes.""" | |
_setattr(node, "USD_ATTR_subdivisionScheme", value) | |
def set_usd_facevarying_linear_interpolation(node, value: Literal["none", "cornersOnly", "cornersPlus1", "cornersPlus2", "boundaries", "all", None]): | |
"""Set USD Face-Varying Interpolation rule for mesh texture mapping/shading purposes.""" | |
_setattr(node, "USD_ATTR_faceVaryingLinearInterpolation", value) | |
# Example usage: | |
# Apply to current selection | |
for node in cmds.ls(sl=1): | |
set_usd_purpose(node, "proxy") | |
# set_usd_subdivision_scheme(node, "none") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment