here's my script... can be cpoy/pasted to sublime/Maya Script Editor...
import maya.cmds as cmds
from functools import partial
import os
class SHED_adder():
def __init__(self, fixed=True):
self.win = 'SHED_adder'
self.fixed = fixed
self.name = self.win
## Window args on Init
self.project = 'Project_003'
self.type = 'Shot'
####################################################
####################################################
####################### New scene TAB
def _initUI(self):
####################################################
### Window management
if cmds.window(self.win, exists=True):
cmds.deleteUI(self.win, window=True)
cmds.window(self.win, title=self.win, sizeable=False, mnb = False, mxb = False)
cmds.columnLayout('mainColumn', adjustableColumn=True, w=350, columnAttach=('both', 3), rowSpacing=5, columnWidth=350 )
cmds.rowColumnLayout( parent = 'mainColumn', numberOfColumns=2, rowSpacing= [1,4], columnAttach=[(1, 'left', 5),(2,'both',5)], columnWidth=[(1, 100), (2, 250)] )
cmds.separator(h=2, style='none')
cmds.separator(h=2, style='none')
## Populate Project OptionMenu
cmds.text( label='Project' )
cmds.optionMenu("Project", changeCommand = partial(self.__uiUpdate, menuUpdated = 'Project'))
self.__populateProjects()
## Populate Type OptionMenu
cmds.text( label='Type' )
cmds.optionMenu("Type", changeCommand = partial(self.__uiUpdate, menuUpdated = 'Type'))
self.__populateType()
## Add Informations depending on type (Asset/Shot)...
## Now just a text line, but later, will need refresh with few options
if self.type == 'Asset':
cmds.text( label='Asset Name' )
cmds.textField("assetName", text = 'NewAssetName')
elif self.type == 'Shot':
cmds.text( label='Shot #' )
cmds.textField("ShotID", text = '010')
cmds.showWindow(self.win)
## Call this function when any of the optionsMenu is changed...
## Check if we need refresh the UI
## Update self.VARIABLES concerned...
def __uiUpdate(self, value = None, menuUpdated = None):
## IF Project menuUPDT, no need to refresh window
## only update slf.project var
if menuUpdated == 'Project':
self.project = value
print "Project changed!!! Self project is now equal to: {project}".format(project=self.project)
## Check if the new selected type is different the what it already is...
elif menuUpdated == 'Type' and self.type != value:
print 'Type menu updated from: {oldType} to :{newType}'.format(oldType = self.type, newType = value)
self.type = value
print 'self ', self.win
# self._initUI()
cmds.deleteUI(self.win, window=True)
def __populateProjects(self):
## List of projects from SHOTGUN
# projects list
#project_items = sg.getActiveProjectsNameComboWIP()
project_items = ['Project_001','Project_002','Project_003','Project_004']
projectList = []
for project in project_items:
if project not in projectList:
projectList.append(project)
cmds.menuItem(label = project , parent = "Project")
cmds.optionMenu("Project", edit=True, value = self.project)
def __populateType(self):
typeList = ['Asset', 'Shot']
for types in typeList:
cmds.menuItem(label = types , parent = "Type")
cmds.optionMenu("Type", e=True, value = self.type)
a = SHED_adder()
a._initUI()