Python maya.cmds.scriptJob() Examples

The following are 21 code examples of maya.cmds.scriptJob(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module maya.cmds , or try the search function .
Example #1
Source File: ml_pivot.py    From ml_tools with MIT License 6 votes vote down vote up
def cleanup(self):
        '''
        Clean up the mess we made.
        '''
        try:
            mc.lockNode(self.pivotHandle, lock=False)
            mc.delete(self.pivotHandle)
        except: pass

        try:
            if mc.scriptJob(exists=self.scriptJob):
                mc.scriptJob(kill=self.scriptJob, force=True)
        except: pass

        pivotHandles = mc.ls('*.ml_pivot_handle', o=True)
        if pivotHandles:
            for each in pivotHandles:
                mc.lockNode(each, lock=False)
                mc.delete(each) 
Example #2
Source File: scriptJobs.py    From mGui with MIT License 5 votes vote down vote up
def __init__(self, scriptJobFlag, eventType, **kwargs):
        self.script_flag = scriptJobFlag
        self.event_type = eventType
        super(ScriptJobEvent, self).__init__(**kwargs)
        self.data['scriptJob'] = -1 
Example #3
Source File: ml_pivot.py    From ml_tools with MIT License 5 votes vote down vote up
def editPivotHandle(self):

        qt_maya_window.installEventFilter(self.keypressFilter)

        #create transform
        self.pivotHandle = mc.group(em=True, name='Adjust_Pivot')
        mc.setAttr(self.pivotHandle+'.rotate', lock=True)
        mc.setAttr(self.pivotHandle+'.rx', keyable=False)
        mc.setAttr(self.pivotHandle+'.ry', keyable=False)
        mc.setAttr(self.pivotHandle+'.rz', keyable=False)
        mc.setAttr(self.pivotHandle+'.scale', lock=True)
        mc.setAttr(self.pivotHandle+'.sx', keyable=False)
        mc.setAttr(self.pivotHandle+'.sy', keyable=False)
        mc.setAttr(self.pivotHandle+'.sz', keyable=False)
        mc.setAttr(self.pivotHandle+'.visibility', lock=True, keyable=False)
        mc.setAttr(self.pivotHandle+'.displayHandle', True)

        self.pivotHandle = mc.parent(self.pivotHandle, self.node)[0]

        mc.addAttr(self.pivotHandle, ln='ml_pivot_handle', at='bool', keyable=False)

        #set initial position
        mc.setAttr(self.pivotHandle+'.translate', *mc.getAttr(self.node+'.rotatePivot')[0])

        #lock it so you don't delete it or something.
        mc.lockNode(self.pivotHandle, lock=True)

        self.scriptJob = mc.scriptJob(event=['SelectionChanged', self.cleanup], runOnce=True)

        mc.setToolTo('Move')

        mc.inViewMessage( amg='After moving the pivot, press <hl>Return</hl> to bake or <hl>Esc</hl> to cancel.', pos='midCenterTop', fade=True, fadeStayTime=4000, dragKill=True) 
Example #4
Source File: ml_pivot.py    From ml_tools with MIT License 5 votes vote down vote up
def __init__(self):

        self.node = None
        self.pivotHandle = None
        self.scriptJob = None
        self.keypressFilter = PivotKeypressFilter(self.bakePivot, self.cleanup) 
Example #5
Source File: shelf.py    From SiShelf with MIT License 5 votes vote down vote up
def make_quit_app_job():
    pm.scriptJob(e=("quitApplication", pm.Callback(quit_app))) 
Example #6
Source File: shelf.py    From SiShelf with MIT License 5 votes vote down vote up
def showEvent(self, event):
        if self.select_parts_script_job is not None:
            return
        self.select_parts_script_job = cmds.scriptJob(e=["SelectionChanged", lambda: self.set_stylesheet()],
                                                      protected=True) 
Example #7
Source File: shelf.py    From SiShelf with MIT License 5 votes vote down vote up
def hideEvent(self, event):
        if self.edit_lock is False:
            if lib.maya_version() < 2017:
                lib.floating_save(self)
                #if self._floating_save is False:
                #    lib.floating_save(self)
                #self._floating_save = True

        if self.select_parts_script_job is None:
            return
        if not cmds.scriptJob(ex=self.select_parts_script_job):
            return
        cmds.scriptJob(kill=self.select_parts_script_job, force=True)
        self.select_parts_script_job = None 
Example #8
Source File: scriptJobs.py    From mGui with MIT License 5 votes vote down vote up
def __init__(self, attrib, **kwargs):
        super(AttributeDeleted, self).__init__("attributeDeleted", attrib, **kwargs)
        self.attribute = attrib


# ======================================================================================================================
# Event based script jobs
#
# See maya docs for more on the distinction between scriptJob -e, scriptJob -ct , etc
# ====================================================================================================================== 
Example #9
Source File: scriptJobs.py    From mGui with MIT License 5 votes vote down vote up
def running(self):
        sid = self.data['scriptJob']
        return sid != -1 and cmds.scriptJob(exists=sid)


# ======================================================================================================================
# Attribute  based script jobs
#
# See maya docs for more on the distinction between scriptJob -e, scriptJob -ct , etc
# ====================================================================================================================== 
Example #10
Source File: scriptJobs.py    From mGui with MIT License 5 votes vote down vote up
def kill(self):
        if self.data.get('scriptJob') > 0:
            cmds.scriptJob(k=self.data['scriptJob'])
            self.data['scriptJob'] = -1
            Logger.info('kill scriptJob %s' % self.__class__) 
Example #11
Source File: scriptJobs.py    From mGui with MIT License 5 votes vote down vote up
def start(self, **sjFlags):
        kwargs = {self.script_flag: (self.event_type, self)}
        kwargs.update(sjFlags)
        self.data['scriptJob'] = cmds.scriptJob(**kwargs)
        Logger.info('start scriptJob %s' % self.__class__) 
Example #12
Source File: dpAutoRig.py    From dpAutoRigSystem with GNU General Public License v2.0 5 votes vote down vote up
def jobReloadUI(self, *args):
        """ This scriptJob active when we got one new scene in order to reload the UI.
        """
        import maya.cmds as cmds
        cmds.select(clear=True)
        cmds.evalDeferred("import sys; sys.modules['dpAutoRigSystem.dpAutoRig'].DP_AutoRig_UI()", lowestPriority=True) 
Example #13
Source File: maya_warpper.py    From pipeline with MIT License 5 votes vote down vote up
def kill_scriptjob(job = None):
    if job:

        return cmds.scriptJob(kill = job, f = True) 
Example #14
Source File: maya_warpper.py    From pipeline with MIT License 5 votes vote down vote up
def create_scriptjob(parent = None, event = None, script = None):
    if event and script:

        return cmds.scriptJob(e=[event,script], ro=False, p = parent) 
Example #15
Source File: append_polygon.py    From SISideBar with MIT License 5 votes vote down vote up
def remove_job(self):
        if self.script_job:
            print 'remove append job :', self.script_job
            cmds.scriptJob(k=self.script_job)
            self.script_job = None 
Example #16
Source File: append_polygon.py    From SISideBar with MIT License 5 votes vote down vote up
def create_job(self):
        cmds.selectMode(co=True)
        #cmds.select(cl=True)
        self.reset_var()
        self.script_job = cmds.scriptJob(cu=True, e=("SelectionChanged", qt.Callback(self.append_polygon)))
        self.undo_flag = False
        print 'create append job :', self.script_job 
Example #17
Source File: append_polygon.py    From SISideBar with MIT License 5 votes vote down vote up
def remove_undo_job(self):
        if self.undo_job:
            cmds.scriptJob(k=self.undo_job)
            self.undo_job = None 
Example #18
Source File: append_polygon.py    From SISideBar with MIT License 5 votes vote down vote up
def create_undo_job(self):
        self.undo_job = cmds.scriptJob(cu=True, e=("Undo", self.undo_control)) 
Example #19
Source File: transform.py    From SISideBar with MIT License 5 votes vote down vote up
def match_transform(mode='', child_comp=False):
    from . import sisidebar_sub
    pre_sel = cmds.ls(sl=True, l=True)
    selection = cmds.ls(sl=True, l=True, type='transform')
    if not selection:
        return
    cmds.undoInfo(openChunk=True)
    set_maching(nodes=selection, mode=mode ,pre_sel=pre_sel, child_comp=child_comp)
    
    msg = lang.Lang(en=u"<hl>Select Matching Object</hl>",
                            ja=u"<hl>一致対象オブジェクトを選択してください</hl>")
    cmds.inViewMessage( amg=msg.output(), pos='midCenterTop', fade=True )
    #cmds.select(cl=True)
    maching_tool = cmds.scriptCtx( title='Much Transform',
                        totalSelectionSets=3,
                        cumulativeLists=True,
                        expandSelectionList=True,
                        toolCursorType="edit",
                        setNoSelectionPrompt='Select the object you want to matching transform.'
                        )
    #カスタムカーソルを設定
    image_path = os.path.join(os.path.dirname(__file__), 'icon/')
    my_cursor = QCursor(QPixmap(image_path+'picker.png'))
    QApplication.setOverrideCursor(my_cursor)
    #cmds.hudButton('HUDHelloButton', e=True, s=7, b=5, vis=1, l='Button', bw=80, bsh='roundRectangle', rc=match_cancel )
    global hud_but
    if maya_ver != 2017:
        try:
            hud_but = cmds.hudButton('HUD_match_cancel', s=7, b=5, vis=1, l='Cancel', bw=80, bsh='roundRectangle', rc=finish_matching)
            #print 'create'
        except:
            #print 'change'
            hud_but = cmds.hudButton('HUD_match_cancel',e=True, s=7, b=5, vis=1, l='Cancel', bw=80, bsh='roundRectangle', rc=finish_matching)
    jobNum = cmds.scriptJob(ro=True, e=('SelectionChanged', qt.Callback(trs_matching)), protected=True)
    sisidebar_sub.get_matrix() 
Example #20
Source File: AEsporeNodeTemplate.py    From spore with MIT License 5 votes vote down vote up
def add_script_job(self):
        """ add a tool changed script job """

        self.logger.debug('Add tool changed script job')
        self.jobs.append(cmds.scriptJob(event=["ToolChanged", self.tool_changed])) 
Example #21
Source File: dpAutoRig.py    From dpAutoRigSystem with GNU General Public License v2.0 4 votes vote down vote up
def jobSelectedGuide(self):
        """ This scriptJob read if the selected item in the scene is a guideModule and reload the UI.
        """
        # run the UI part:
        selectedGuideNodeList = []
        selectedList = []

        # get selected items:
        selectedList = cmds.ls(selection=True, long=True)
        if selectedList:
            updatedGuideNodeList = []
            needUpdateSelect = False
            for selectedItem in selectedList:
                if cmds.objExists(selectedItem+"."+GUIDE_BASE_ATTR) and cmds.getAttr(selectedItem+"."+GUIDE_BASE_ATTR) == 1:
                    if not ":" in selectedItem[selectedItem.rfind("|"):]:
                        newGuide = self.setupDuplicatedGuide(selectedItem)
                        updatedGuideNodeList.append(newGuide)
                        needUpdateSelect = True
                    else:
                        selectedGuideNodeList.append(selectedItem)
            if needUpdateSelect:
                self.jobReloadUI()
                cmds.select(updatedGuideNodeList)

        # re-create module layout:
        if selectedGuideNodeList:
            for moduleInstance in self.moduleInstancesList:
                cmds.button(moduleInstance.selectButton, edit=True, label=" ", backgroundColor=(0.5, 0.5, 0.5))
                for selectedGuide in selectedGuideNodeList:
                    selectedGuideInfo = cmds.getAttr(selectedGuide+"."+MODULE_INSTANCE_INFO_ATTR)
                    if selectedGuideInfo == str(moduleInstance):
                        moduleInstance.reCreateEditSelectedModuleLayout(bSelect=False)
        # delete module layout:
        else:
            try:
                cmds.frameLayout('editSelectedModuleLayoutA', edit=True, label=self.langDic[self.langName]['i011_selectedModule'])
                cmds.deleteUI("selectedColumn")
                for moduleInstance in self.moduleInstancesList:
                    cmds.button(moduleInstance.selectButton, edit=True, label=" ", backgroundColor=(0.5, 0.5, 0.5))
            except:
                pass
        
        # re-select items:
        #if selectedList:
        #    cmds.select(selectedList)
        # call reload the geometries in skin UI:
        self.reloadPopulatedGeoms()