Created
October 3, 2018 13:19
-
-
Save hotcakesdeluxe/81f7edc9041a032d69c093d91ee6b54e to your computer and use it in GitHub Desktop.
Autodesk Maya script to insert a number of joints at equal spacing on existing bone
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import maya.cmds as cmds | |
from maya import cmds, OpenMaya | |
def AddBones(): | |
cmds.select() | |
sel = cmds.ls(sl=True) | |
if len(sel) == 0: | |
cmds.error("No Joints Selected") | |
cuts = input("Number of joints: ") | |
relSel = cmds.listRelatives(sel, children = True) | |
sel.extend(relSel) | |
start = cmds.xform(sel[0], q = 1, ws =1, t =1) | |
end = cmds.xform(sel[1], q = 1, ws =1, t =1) | |
startV = OpenMaya.MVector(start[0], start[1], start[2]) | |
endV = OpenMaya.MVector(end[0], end[1], end[2]) | |
splitVector = (endV - startV) | |
segmentVector = (splitVector/(cuts+1)) | |
segmentLoc = startV + segmentVector | |
curParent = sel[0] | |
for i in range(0, cuts): | |
if i == 0: | |
seg = cmds.duplicate(curParent, parentOnly = True)[0] | |
seg = cmds.rename(seg, curParent+"_twist_01") | |
cmds.parent(seg, curParent) | |
cmds.xform(seg, ws =1, t= (segmentLoc.x, segmentLoc.y, segmentLoc.z)) | |
curParent = seg | |
else: | |
seg = cmds.duplicate(curParent)[0] | |
num = i + 1 | |
print num | |
seg = cmds.rename(seg, sel[0]+"_twist_0"+str(num)) | |
cmds.parent(seg, curParent) | |
cmds.xform(seg, ws =1, t= (segmentLoc.x, segmentLoc.y, segmentLoc.z)) | |
curParent = seg | |
segmentLoc = segmentLoc + segmentVector | |
for child in relSel: | |
cmds.parent(child,curParent) | |
AddBones() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment