我已经为一个工具写了一段代码,当在maya中选择一个连接时,当这个连接被选择时,用户在工具的界面上按下一个按钮,它应该将连接重新命名为按钮的文本。代码在maya的脚本编辑器中编译,工具UI显示正确。但是,当您选择一个连接,然后按下jnt_L_toe按钮(目前应该工作的唯一一个),联合名称不会被jnt_L_toe取代,我的问题是为什么?
以下是代码:
#Global variable contains all joints in model
joints_list = maya.cmds.ls(type="joint")
#Variable names
Ltoe = "jnt_L_toe"
# create the window
wnd_name = maya.cmds.window(title="Rename-A-Joint", widthHeight=[300, 500])
# create the layout
maya.cmds.rowColumnLayout(numberOfColumns = 2, rowSpacing=[(1,5), (2,5)], columnWidth=[(1,120),(2,120)] )
maya.cmds.text(label="Please select a \n joint then one\n of the following\n buttons to rename it:", font = "boldLabelFont")
maya.cmds.text(label=" \n \n ", font = "boldLabelFont")
# create the controls
maya.cmds.text(label="Legs", font = "boldLabelFont")
maya.cmds.text(label="Hands", font = "boldLabelFont")
maya.cmds.button(label="jnt_L_toe", command="renameJoint(Ltoe)")
maya.cmds.button(label="jnt_L_thumb1", command="pass")
maya.cmds.button(label="jnt_L_ball", command="pass")
maya.cmds.button(label="jnt_L_thumb2", command="pass")
maya.cmds.button(label="jnt_L_ankle", command="pass")
maya.cmds.button(label="jnt_L_thumb3", command="pass")
maya.cmds.button(label="jnt_L_knee", command="pass")
maya.cmds.button(label="jnt_L_thumb4", command="pass")
maya.cmds.button(label="jnt_L_thigh", command="pass")
maya.cmds.button(label="jnt_L_thumb5", command="pass")
maya.cmds.text(label="Arms", font = "boldLabelFont")
maya.cmds.button(label="jnt_L_index1", command="pass")
maya.cmds.button(label="jnt_L_clavicle", command="pass")
maya.cmds.button(label="jnt_L_index2", command="pass")
maya.cmds.button(label="jnt_L_shoulder", command="pass")
maya.cmds.button(label="jnt_L_index3", command="pass")
maya.cmds.button(label="jnt_L_elbow", command="pass")
maya.cmds.button(label="jnt_L_index4", command="pass")
maya.cmds.button(label="jnt_L_forearm", command="pass")
maya.cmds.button(label="jnt_L_middle1", command="pass")
maya.cmds.button(label="jnt_L_wrist", command="pass")
maya.cmds.button(label="jnt_L_middle2", command="pass")
maya.cmds.text(label="")
maya.cmds.button(label="jnt_L_middle3", command="pass")
maya.cmds.text(label="")
maya.cmds.button(label="jnt_L_middle4", command="pass")
maya.cmds.text(label="")
maya.cmds.button(label="jnt_L_ring1", command="pass")
maya.cmds.text(label="")
maya.cmds.button(label="jnt_L_ring2", command="pass")
maya.cmds.text(label="")
maya.cmds.button(label="jnt_L_ring3", command="pass")
maya.cmds.text(label="")
maya.cmds.button(label="jnt_L_ring4", command="pass")
maya.cmds.text(label="")
maya.cmds.button(label="jnt_L_pinky1", command="pass")
maya.cmds.text(label="")
maya.cmds.button(label="jnt_L_pinky2", command="pass")
maya.cmds.text(label="")
maya.cmds.button(label="jnt_L_pinky3", command="pass")
maya.cmds.text(label="")
maya.cmds.button(label="jnt_L_pinky4", command="pass")
# show the window
maya.cmds.showWindow(wnd_name)
#Function to change name of joint
def renameJoint(name):
currentjoint = cmds.ls(type = "joint", selection=True)
for connect in joints_list:
if(connect == currentjoint):
cmds.rename(connect, 'name')`发布于 2014-01-06 15:36:07
每看一遍代码都没有问题。这就是你所显示的代码之外的问题。您不能真正使用python片段而忽略import语句,因为这些语句是故事的核心内容。此外,您还应该在一般张贴报告的错误。
最可能的问题是,您在函数中使用的命名空间与在您的身体中使用的名称空间不同。请参见在主体中使用maya.cmds,这表明您已经导入了:
import maya.cmds另一方面,该函数使用cmds,表示:
import maya.cmds as cmd到目前为止,这是普遍的惯例,两者都做没有真正的意义。然而,很难说出你真正缺失的问题。
另一个错误可以在以下文件中找到:
def renameJoint(name):
currentjoint = cmds.ls(type = "joint", selection=True)
for connect in joints_list:
if(connect == currentjoint):
cmds.rename(connect, 'name')`这可能应该是:
def renameJoint(name):
currentjoint = cmds.ls(type = "joint", selection=True)
for connect in joints_list:
if(connect == currentjoint[0]):
cmds.rename(connect, name)有点神秘但确定。无论如何,我建议您将代码更改为:
import maya.cmds as cmds
def renameJoint(name):
currentjoint = cmds.ls(type = "joint", selection=True)
if currentjoint[0] in joints_list:
cmds.rename(currentjoint[0], name)
def multipleButtonGrp(title,lst):
cmds.text(label=title, font = "boldLabelFont")
cmds.text(label="")
for item in lst:
cmds.button(item, label=item, command="renameJoint('%s')"%item)
joints_list = maya.cmds.ls(type="joint")
wnd_name = cmds.window(title="Rename-A-Joint", widthHeight=[300, 500])
cmds.rowColumnLayout(numberOfColumns = 2) #add your options
multipleButtonGrp("Hands",
["jnt_L_toe", "jnt_L_thumb1",
"jnt_L_ball", "jnt_L_thumb2",
"jnt_L_ankle", "jnt_L_thumb3",
"jnt_L_knee", "jnt_L_thumb4",
"jnt_L_thigh", "jnt_L_thumb5"])
cmds.showWindow(wnd_name)https://stackoverflow.com/questions/20943263
复制相似问题