Reputation: 9
I am trying to write a script that, on button press with a joint selected, will copy the transform values from the selected joint(s) and then create a controller selected from an option menu. My problem is getting the code to read the option menu. I've tried several variations and all say there is no option menu with the selected name.
Code follows....
import maya.cmds as maya
def testWin():
winName = maya.window(title="test", rtf = True, mxb = False)
maya.columnLayout()
maya.button(label = "run test", c = "test()")
shapeMenu = maya.optionMenu( label='Shape Menu', changeCommand="test()" )
maya.menuItem( label='Circle' )
maya.menuItem( label='Square' )
maya.menuItem( label='Triangle' )
maya.showWindow(winName)
testWin()
def test():
sel = maya.ls(type = "joint", sl=True)
if not sel:
print "select at least 1 JOINT"
else:
new_pos = maya.xform(q=True, t=True, ws=True)
new_rot = maya.xform(q=True, rotation=True, ws=True)
shape = maya.optionMenu("Shape Menu", q = True, value = True)
if shape == "Circle":
new_control = maya.circle(center = new_pos)
elif shape == "Square":
new_control = maya.nurbsSquare(center = new_pos)
elif shape == "Triangle":
new_control = maya.circle(center = new_pos, degree = 1, sections = 3)
Upvotes: 0
Views: 287
Reputation: 12208
You can't be sure that maya will give you the name you asked for when creating a GUI object -- an in this case it will never work because the name that comes back will not have the space.
You should capture the name of the option menu by returning the value of shapeMenu
from your testWin()
function then use that in your test()
function
Upvotes: 1