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…