Maya Python referencing optionMenu returns as non-existent

Dalia Hileman Source

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)
pythonmayaoptionmenu

Answers

comments powered by Disqus