Dharmin Doshi
Dharmin Doshi

Reputation: 21

How to create a NURBS circle for each joint in the scene by using the Maya Python lib?

I needed some help in python regarding getting joint list in Maya. I am a newbie, so still learning. Here is what I am trying to do: - For each joints or joints existing in the scene, I want to create a NURBS circle for each joint and match its position to the joints in the scene. Here is what I have so far:

selected = cmds.ls(sl=True) #First joint selected)
joint_translate = cmds.xform(selected[1], query=True, translation=True, worldSpace=True) #first joint translation value. 
joint_rotate = cmds.xform(selected[1], query=True, rotation=True, worldSpace=True) #first joint rotation value. 
cmds.xform(selected[0], translation=joint_translate, worldSpace=True) #matching whatever is selected to the first joint. 
cmds.xform(selected[0], rotation=joint_rotate, worldSpace=True)

But I want to store all the translation and rotations values without selecting them. How can I store each joints transformation values and how can I store each joint's name. Then create circle and match it to each of the joints. I know I do have to use a for loop for this. I did this:

joints = cmds.ls(type='joint')
selected = cmds.ls(sl=True)
joint_translate = cmds.xform(selected[0], query=True, translation=True, worldSpace=True)
joint_rotate = cmds.xform(selected[0], query=True, rotation=True, worldSpace=True)
cmds.circle(nr=(1,0,0), c=(0, 0, 0), r=1.5, n='Circle1')
cmds.xform('Circle1', translation=joint_translate, worldSpace=True)
cmds.xform('Circle1', rotation=joint_rotate, worldSpace=True)

but it just works for first joint(which I am aware of), but I use the exact name to match it(that's why it worked). I want to do this without using the name of circle.

The whole point is to just create NURBS circle for each joints in the scene. The joints could be 3 or 5 or 20.

Any help is greatly appreciated :)

Upvotes: 0

Views: 2646

Answers (1)

Achayan
Achayan

Reputation: 5885

Did you tried a simple for loop for your issue ?

joints = cmds.ls(type='joint')
for eachJoint in joints:
    joint_translate = cmds.xform(eachJoint, query=True, translation=True, worldSpace=True)
    joint_rotate = cmds.xform(eachJoint, query=True, rotation=True, worldSpace=True)
    newCircl = cmds.circle(nr=(1,0,0), c=(0, 0, 0), r=1.5, n='Circle1_%s' % eachJoint)
    cmds.xform(newCircl[0], translation=joint_translate, worldSpace=True)
    cmds.xform(newCircl[0], rotation=joint_rotate, worldSpace=True)

Upvotes: 1

Related Questions