View Full Version : CurveToBones in python

03-27-2010, 06:09 PM
Hello there;
i'm trying to convert the curveToBones.mel, a bonus tool from autodesk to python
so this what i've done:
import maya.cmds as mc

def curveToJoint(numBones):
curves = mc.ls (selection = True)
for curve in curves:
mc.select (clear = True)
curveInfo = mc.pointOnCurve (curve, constructionHistory = 1)
mc.setAttr ( curveInfo + ".turnOnPercentage", 1)
joints = []
for i in range (1, numBones):
parameter = i * (1.0/numBones)
mc.setAttr ( curveInfo + ".parameter", parameter)
position = mc.getAttr (curveInfo + ".position")
joints[i] = mc.joint (position = (position[0][0],
position[0][2]) )
mc.delete (curveInfo)
mc.joint (joints, edit = True, orientJoint = "xyz")
but maya creates 1 joint and give me this error:
# Error: IndexError: list assignment index out of range #
and idea about that ?
thanks for Help !

03-27-2010, 07:20 PM
try this:

position = mc.getAttr (curveInfo + ".position")[0]
joints.append(mc.joint (position = position))

and Im not sure if mc.joint returns list or string. if its list then you can do this:
joints.append(mc.joint (position = position)[0])

03-27-2010, 08:39 PM
thanks for your answer
actually, i think that the mc.joint command returns a list with a tuple in it
and appending a list by a the joint command, returns an error syntax
any idea ?

03-27-2010, 10:36 PM
No it returns a string which is the name of the created joint. and I recreated part of your code and didnt get any syntax errors..

import maya.cmds as mc

def test():
joints = []
for i in range (1, 5):
position = [1*i, 5*i, 2*i]
joints.append(mc.joint (position = position))

mc.joint (joints, edit = True, orientJoint = "xyz")


03-27-2010, 11:40 PM
my bad, actualy the getAttr returns a tuple in a list
and thanks a lot for your help
that was really Helpfull

CGTalk Moderation
03-27-2010, 11:40 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.