Skip to content

Instantly share code, notes, and snippets.

@BigRoy
Last active September 13, 2024 07:02
Show Gist options
  • Save BigRoy/87aeef2748c5bf8eab95bac392752427 to your computer and use it in GitHub Desktop.
Save BigRoy/87aeef2748c5bf8eab95bac392752427 to your computer and use it in GitHub Desktop.
Maya shapes with components are returned as "transform.component"

When doing face assignments or other component members into a set and then query cmds.sets(my_set, query=True) you get the members like:

  • pCube1.f[0:4]

Instead of

  • pCubeShape1.f[0:4]

For whatever reason someone thought it would be nice to make it look as if the components are on the transform instead of shape. Does anyone know a maya command to expand that to the shape?

I could of course do:

from maya import cmds


def expand(member: str) -> str:
    if "." in member:
        node, components = member.split(".", 1)
        if not cmds.objectType(node, isAType="shape"):
            shape = cmds.listRelatives(node, shapes=True)[0]
            node = f"{node}|{shape}"
        member = f"{node}.{components}"
    return member

That is assuming only shapes can have components

For example:

# Example
cube = cmds.polyCube()[0]
s = cmds.sets(f"{cube}.f[0:4]")
members = cmds.sets(s, query=True)
print(members)
['pCube1.f[0:4]']
print([expand(member) for member in members])
['pCube1|pCubeShape1.f[0:4]']

But I wonder if there's a better way. Do note that maya does 'auto-expand' to the shape as soon as there is more than one shape underneath the transform:

cube = cmds.polyCube()[0]
s = cmds.sets(f"{cube}.f[0:4]")
cmds.createNode("lattice", parent=cube)
members = cmds.sets(s, query=True)
print(members)
# ['pCubeShape1.f[0:4]']

There must be a simple maya command for this that I'm missing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment