Python Code for Selecting only Joints in a Scene

I’m trying to create a loop that will cycle through a scene query for joints and create a locator on each joint, using python, any Ideas ?

you can just use the ls command:
allJoints ="joint")
this will select all joints in the scene

1 Like

Thanks you !..actually it assigned all the joints in the scene to the allJoints variable as a list .

You kind of asked one thing in the title and something more in depth in the post.

This should do the trick (continuing from where peeker88 started)

allJoints ="joint")

for join in allJoints:
   joint_position = cmds.xform(join, q=True, ws=True, t=True)
   cmds.spaceLocator(a=True, p=joint_position)

So Im trying to do the same loop but for this one I want to create a group node for each finger joint and snap their pivots to the joints. Here is what I have so far. It needs work:

~FJoints =“L_R*”, type=“joint”)
for jnt in FJoints:
joint_position = cmds.xform(jnt, q=True, ws=True, t=True)
groups = em=True, name=‘null1’ )
cmds.MatchTransform(groups, joint_position)~

not sure if matchTransform works in world space or object space. This is why I would use xform instead, where I can specify the space. Otherwise seems good. Are you working on an animation mirroring script?

I really like PyMel for this kind of stuff

import pymel.core as pm

joints ='L_R*', type='joint')
for joint in joints:
    group = pm.createNode('transform', name=f'{joint}_grp')
    tr = joint.getTranslation(worldSpace=True)
    group.setTranslation(tr, worldSpace=True)

You can also .getMatrix() and .setMatrix() on nodes if you want translate + rotate + scale together and it’s a bit nicer than using xform.

If you already have a large chunk of this built in cmds though then there might not be a good reason to switch to PyMel. In Maya 2024 it doesn’t come pre-installed and you have to pip-install it.