In Python, PyMel why does embeded for loops only add menu items to second menu?

32 views Asked by At

when I loop through a list of menu's and list of menuItem labels, menuItems only show up in the second menu, twice. my code looks like:

import pymel.core as pm

pm.window('aim_window')
pm.columnLayout()
aim_mnu = pm.optionMenuGrp(l = 'set aim axis:')
up_mnu = pm.optionMenuGrp(l = 'set up axis:')

axes = ['pX', 'pY', 'pZ', 'nX', 'nY', 'nZ']

for mnu in [aim_mnu, up_mnu]:
    pm.setParent(mnu)
    for ax in axes:
        pm.menuItem(l = ax)
pm.showWindow('aim_window')

the aim_mnu is empty (it's also empty if I reverse the order in the for statement) and I get double menuItems in the up_mnu. why is that?

if I explicitly tell the menuItem's parent to be a specific menu I get an error of

# RuntimeError: Menu Item's menu not found. # 

so that's not a work around

1

There are 1 answers

0
rasonage On

ok so for setting the parent to an optionMenuGrp, one has to add the string '|OptionMenu' after the name of the optionMenuGrp so

pm.setParent(mnu)

should look like

pm.setParent(mnu + '|OptionMenu', m = True) #though m = True isn't needed