I've written a piece of code for a tool that should, when a joint is selected in maya and whilst the joint is selected the user presses a button on the interface of the tool it should re-name the joint to the text of the button. The code compiles in maya's script editor and the tool UI appears correctly. However when you select a joint then press on the jnt_L_toe button (the only one that should be currently working), the joint name is not replaced with jnt_L_toe, and my question is why?
Here is the code:
#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')`