Message 1 of 9
Trouble with writing a script that can create and constrain a joints
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hey guys I am new to maya scripting. I am trying to write a script that can create and constrain joints at selected vertexes. I found someone already done the creating joints part and i tried to "point on poly" constrain each created joints to each corresponding vertex during the loop. However the joints will all ends up constraining at the same vertex. What am I doing wrong?
import maya.cmds as cmds def componentToJoint(): if cmds.objectType(cmds.ls(sl=1)[0]) != "mesh": return # return the selection as a list selList = getSelection() print selList componentType = selList[0][selList[0].index(".") + 1:selList[0].index("[")] componentCenters = [] jointNum = 1 for c in selList: cmds.select(cl=1) cmds.joint(n="joint" + str(jointNum), p=cmds.pointPosition(c), rad=.25)
#point on poly constraint - doesnt work cmds.pointOnPolyConstraint(c, "joint" + str(jointNum) ) jointNum += 1 cmds.select(cl=1) def getSelection(): components = cmds.ls(sl=1) selList = [] objName = components[0][0:components[0].index(".")] # go through every component in the list. If it is a single component ("pCube1.vtx[1]"), add it to the list. Else, # add each component in the index ("pCube1.vtx[1:5]") to the list for c in components: if ":" not in c: selList.append(c) else: print c startComponent = int(c[c.index("[") + 1: c.index(":")]) endComponent = int(c[c.index(":") + 1:c.index("]")]) componentType = c[c.index(".") + 1:c.index("[")] while startComponent <= endComponent: selList.append(objName + "." + componentType + "[" + str(startComponent) + "]") startComponent += 1 return selList componentToJoint()
Heres the screen shot
each vertexes are cramped into one single point