Reputation: 13
I can find one other place where this problem is specifically addressed, but it seems to be even more personal in nature and the other thread provided no help. This is the error:
# Error: Maya command error
# Traceback (most recent call last):
# File "<maya console>", line 1, in <module>
# File "<maya console>", line 26, in createJoints
# RuntimeError: Maya command error #
And here is the code, to create a chain of joints along a premade curve:
import maya.cmds as mc
##UI##
jointCurve = mc.window(title = "Create Joint Chain") #window title#
mc.rowColumnLayout(nc = 2) #divides window into two columns#
mc.text(l = "Number of Joints") #dialog prompt#
jntAmount = mc.intField (v = 5, min = 2) #default value of 5, minimum value of 2 joints#
mc.button(l = "Create", w = 150, c = "createJoints()") #confirms entry#
mc.button(l = "Cancel", w = 150, c = "mc.deleteUI(jointCurve)") #closes window, deletes UI#
mc.showWindow() #now that all parameters are defined, the window is opened#
##Method##
def createJoints():
#Gathering Information#
selCurve = mc.ls(sl = True) [0]
jointAmount = mc.intField(jntAmount, q = True, v = True)
prevJnt = ""
rootJnt = ""
for i in range(0, jointAmount): #for each increment from 0 to the amount defined in the field,#
mc.select(cl = True) #clear the selection,#
newJnt = mc.joint() #create a joint,#
motionPath = mc.pathAnimation(newJnt, c = selCurve, fractionMode = True) #affix to curve using a motion path,#
mc.cutKey(motionPath + ".u", time = ()) #remove animation keys from joint's U value (position on curve),#
mc.setAttr(motionPath + ".u", i * (1.0/(jointAmount - 1))) #distribute joints evenly along curve#
#delete motion path#
mc.delete(newJnt + ".tx", icn = True)#deletes x translate value's input connections#
mc.delete(newJnt + ".ty", icn = True)#deletes y translate value's input connections#
mc.delete(newJnt + ".tz", icn = True)#deletes z translate value's input connections#
mc.delete(motionPath) #deletes motion path itself#
if i == 0:
prevJnt = newJnt
rootJnt = newJnt
continue #skips next instructions for root joint since it has no parent#
mc.parent(newJnt, prevJnt) #parents current joint to previous joint#
prevJnt = newJnt #sets status of "previous" joint to current joint#
mc.joint(rootJnt, e = True, oj = "xyz", sao = "yup", ch = True, zso = True) #orients joints along chain#
mc.deleteUI(jointCurve) #closes prompt window#
Whenever I run the code in a new file, it works perfectly, no issues.
But I have another file that, when I run this code, it throws the above error.
So it looks like it's having a problem somewhere with importing Maya commands? as well as with this line, in particular:
mc.cutKey(motionPath + ".u", time = ())
For some reason, this error is thrown even when I start a new file, and import the other file into the scene.
I have absolutely no idea where to start looking..
Upvotes: 0
Views: 293
Reputation: 2512
The issue is your ui which is prior to the creation of your command
import maya.cmds as mc
from functools import partial
##Method##
def createJoints(*args):
#Gathering Information#
selCurve = mc.ls(sl = True) [0]
jointAmount = mc.intField(jntAmount, q = True, v = True)
prevJnt = ""
rootJnt = ""
for i in range(0, jointAmount): #for each increment from 0 to the amount defined in the field,#
mc.select(cl = True) #clear the selection,#
newJnt = mc.joint() #create a joint,#
motionPath = mc.pathAnimation(newJnt, c = selCurve, fractionMode = True) #affix to curve using a motion path,#
mc.cutKey(motionPath + ".u", time = ()) #remove animation keys from joint's U value (position on curve),#
mc.setAttr(motionPath + ".u", i * (1.0/(jointAmount - 1))) #distribute joints evenly along curve#
#delete motion path#
mc.delete(newJnt + ".tx", icn = True)#deletes x translate value's input connections#
mc.delete(newJnt + ".ty", icn = True)#deletes y translate value's input connections#
mc.delete(newJnt + ".tz", icn = True)#deletes z translate value's input connections#
mc.delete(motionPath) #deletes motion path itself#
if i == 0:
prevJnt = newJnt
rootJnt = newJnt
continue #skips next instructions for root joint since it has no parent#
mc.parent(newJnt, prevJnt) #parents current joint to previous joint#
prevJnt = newJnt #sets status of "previous" joint to current joint#
mc.joint(rootJnt, e = True, oj = "xyz", sao = "yup", ch = True, zso = True) #orients joints along chain#
mc.deleteUI(jointCurve) #closes prompt window#
def cancelUI(jointCurve, *args):
mc.deleteUI(jointCurve)
##UI##
jointCurve = mc.window(title = "Create Joint Chain") #window title#
mc.rowColumnLayout(nc = 2) #divides window into two columns#
mc.text(l = "Number of Joints") #dialog prompt#
jntAmount = mc.intField (v = 5, min = 2) #default value of 5, minimum value of 2 joints#
mc.button(l = "Create", w = 150, c = createJoints) #confirms entry#
mc.button(l = "Cancel", w = 150, c = partial(cancelUI, jointCurve)) #closes window, deletes UI#
mc.showWindow() #now that all parameters are defined, the window is opened#
Upvotes: 1