1
我已經爲一個工具編寫了一段代碼,當在maya中選擇一個關節時,當選擇了關節時,用戶按下界面上的按鈕它應該重新命名該按鈕的文本的關節的工具。該代碼在maya的腳本編輯器中編譯,並且工具UI顯示正確。然而,當你選擇一個關節,然後按jnt_L_toe按鈕(唯一應該當前工作的),聯合名稱不會被替換爲jnt_L_toe,我的問題是爲什麼?Python腳本將在maya中編譯但不執行任何操作
下面是代碼:
#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')`
感謝您提供的解決方案。是的,因爲你推斷原始的舊的導入maya.cmds是在開始時使用的(我忘記了包含在代碼中)。然而,整個腳本仍然運行沒有毛刺保存renameJoint函數,其中行if(connect == currentjoint)是妨礙它的東西。您顯然已經爲UI提供了更加雄辯的解決方案。唯一的問題是空白按鈕不應該出現在腿和手臂後的列 - 所以我想檢查是必要的。無論如何再次感謝 - 我沒有15代表,否則我已經投了答案几次:) – Enchanter
不,但你可以接受答案(複選標記),並比你有15分。除了現在你做:) – joojaa