Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import maya.cmds as mc
- class ScriptJobUI(object):
- def __init__(self):
- self.__window = 'SelectEdgeJob'
- self.__currentJobId = None
- # Check to see if the Window exists, Delete Window
- if mc.window(self.__window, query=True, exists=True):
- mc.deleteUI(self.__window)
- # Define window attributes
- self.__window = mc.window(self.__window, title='SelectEdgeJob', sizeable=True)
- # Create menu bar with help
- menuBarLayout = mc.menuBarLayout()
- helpMenu = mc.menu( label='help', tearOff=False )
- howToHelp = mc.menuItem( label='How to use', command=loadHelp)
- # Main Layout of all menu is a form
- mainFormLayout = mc.formLayout()
- menuSeparator = mc.separator(style='in')
- bottomSeparator = mc.separator(style='in')
- # create button to launch function
- startSelectionButton = mc.button(label='Start Selection', command=startScriptJob)
- # create button to complete function
- endtSelectionButton = mc.button(label='End Selection', command=endScriptJob)
- # Position the controls MainForm
- mc.formLayout(mainFormLayout, edit=True, # attach to the form
- attachForm=[
- (menuSeparator, 'top',3),
- (menuSeparator, 'left',3),
- (menuSeparator, 'right',3),
- (startSelectionButton, 'left',3),
- (endtSelectionButton, 'right',3),
- (bottomSeparator, 'left',3),
- (bottomSeparator, 'right',3),
- (bottomSeparator, 'bottom',5),
- ],
- # Attach controls to positions
- attachPosition=[
- (startSelectionButton, 'right', 2, 50),
- (endtSelectionButton, 'left', 2, 50),
- ],
- # Attach controls to other controls
- attachControl=[
- (startSelectionButton, 'top',5,menuSeparator),
- (endtSelectionButton, 'top',5,menuSeparator),
- ],
- )
- def show(self):
- mc.showWindow(self.__window)
- def startScriptJob(self, *args):
- self.endScriptJob() # make sure an old one is dead first
- print 'StartJob'
- newJob = mc.scriptJob(event=['SelectionChanged', self.selectionChanged])
- print 'JOBNUMBER:', newJob
- self.__currentJobId = newJob
- def endScriptJob(self, *args):
- if self.__currentJobId is not None:
- print 'EndJob'
- mc.scriptJob(kill=self.__currentJobId, force=True)
- def loadHelp(self, *args):
- pass
- def selectionChanged(self, *args):
- print 'Script Job Executed!'
- ui = ScriptJobUI()
- ui.show()
Advertisement
Add Comment
Please, Sign In to add comment