Need help with UI and list items and indexes

Hi all, it has been a while for me doing python scripting after about 8 months of hiatus. Really need some insights.
I have been trying to set or modify the camera filmback/film gate attribute via coding and after much trial and errors, I finally found the command for it but now I am meeting with some other issues…

The first item in list, in Python terms - the index usually starts from 0, however in Maya term’s for this filmbackMenu, it starts from 1.


cmds.optionMenu('filmbackMenu', edit = True, select = 0) # Errors-out, stating that it is out of range
cmds.optionMenu('filmbackMenu', edit = True, select = 1) # No errors

Suppose if my filmback Menu is as follows:


list01 = ['itemA-01', 'itemB-02', 'itemC-02', 'itemD-01', 'itemE-01', 'itemF-03']
list01.insert(0,"")
for index, item in enumerate(list01):
    print index, item

while I manage to find a way to have my items start from index ‘1’ by inserting a dummy/blank…
As I am trying to filter out anything that contains ‘-01’ and append both the name and the index into list02, however I only know how to do for either just the name or the index, but I believe I will need both. This is my code section:


list02 = []
for i in list01:
    if '-01' in str(i):
        list02.append(i)
# Result: ['itemA-01', 'itemD-01', 'itemE-01']  # The index here should be 1, 4, 5 

Is it possible to append both the name and the index together? For example, itemA-01 1, ‘itemD-01’ 4 , ‘itemE-01’ 5?
The index need not be shown in the UI, the name will do, still I will need to grab the index value eventually…

Kindly see below for my code, perhaps that may give a better insight and please do feel free to criticize if need be.


from camera_node import Format
import maya.cmds as cmds

list01 = ['itemA-01', 'itemB-02', 'itemC-02', 'itemD-01', 'itemE-01', 'itemF-03']
list01.insert(0,"")
for index, item in enumerate(list01):
    print index, item

list02 = []
for i in list01:
    if '01' in str(i):
        list02.append(i)

window = cmds.window()
cmds.columnLayout()
cmds.optionMenu (label = 'Select a format')
for x in list02:
    cmds.menuItem(label=x)
cmds.button( label = 'Ok')
cmds.button( label = 'Cancel')

cmds.showWindow( window )

What happens in my UI is that, upon the user selection, eg. if I selected itemD-01 which is of index 4, the following code should run:


cmds.optionMenu('filmbackMenu', edit = True, select = 4)

Notice that the flag for select will be changed…

So while I managed to settle the index issue, right now, I am having 2 issues…

  1. The ‘value’ is not exactly returning, as soon as a Format is selected and the OK button is hit… Am I missing something?
  2. How can I make my UI closes upon a OK button has been selected?
import maya.cmds as cmds

def mainCode():
    ...
    ...
    showUI()
    cmds.optionMenu('filmbackMenu', edit = True, value = xxx ) # <-- I want to grab the value from the menu selection and input into this 'value' flag
    ...

def showUI():

    if cmds.window("UI_MainWindow", exists = True):
        cmds.deleteUI("UI_MainWindow")

    cmds.window("UI_MainWindow", title = "User Interface Test", w = 500, h = 700, mnb = False, mxb = False, sizeable = False)
    cmds.columnLayout("UI_MainLayout", w = 300, h =500)

    cmds.optionMenu("UI_FormatMenu", w = 250, label = "Select a Format")

    list01 = ['itemA-01', 'itemB-02', 'itemC-02', 'itemD-01', 'itemE-01', 'itemF-03']
    for x in list01:
        cmds.menuItem(label = str(x))

    cmds.button("UI_SelectButton", label = "OK", w = 200, command=ObjectSelection)

    cmds.showWindow("UI_MainWindow") #shows window

def ObjectSelection(*args):
    currentFormat = cmds.optionMenu("UI_FormatMenu", query=True, value=True)
    print currentFormat
    return currentFormat

Any insights, anyone?

What is this supposed to do? Which menu are you trying to grab from? Yours? Maya’s?

cmds.optionMenu('filmbackMenu', edit = True, value = xxx ) # <-- I want to grab the value from the menu selection and input into this 'value' flag.

Use cmds.deleteUI(windowname) to delete your UI.

[QUOTE=capper;30177]What is this supposed to do? Which menu are you trying to grab from? Yours? Maya’s?

cmds.optionMenu('filmbackMenu', edit = True, value = xxx ) # <-- I want to grab the value from the menu selection and input into this 'value' flag.

[/QUOTE]

That is suppose to change the film back/gate option in the camera - basically the maya menu

The value flag in this case is to be of string, and I am trying to insert a string inside it from my UI, but I am unable to achieve that