Python maya.cmds.timeControl() Examples

The following are 12 code examples of maya.cmds.timeControl(). 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: capture.py    From pyblish-bumpybox with GNU Lesser General Public License v3.0 7 votes vote down vote up
def parse_active_scene():
    """Parse active scene for arguments for capture()

    *Resolution taken from render settings.

    """

    time_control = mel.eval("$gPlayBackSlider = $gPlayBackSlider")

    return {
        "start_frame": cmds.playbackOptions(minTime=True, query=True),
        "end_frame": cmds.playbackOptions(maxTime=True, query=True),
        "width": cmds.getAttr("defaultResolution.width"),
        "height": cmds.getAttr("defaultResolution.height"),
        "compression": cmds.optionVar(query="playblastCompression"),
        "filename": (cmds.optionVar(query="playblastFile")
                     if cmds.optionVar(query="playblastSaveToFile") else None),
        "format": cmds.optionVar(query="playblastFormat"),
        "off_screen": (True if cmds.optionVar(query="playblastOffscreen")
                       else False),
        "show_ornaments": (True if cmds.optionVar(query="playblastShowOrnaments")
                       else False),
        "quality": cmds.optionVar(query="playblastQuality"),
        "sound": cmds.timeControl(time_control, q=True, sound=True) or None
    } 
Example #2
Source File: ui.py    From maya-timeline-marker with GNU General Public License v3.0 6 votes vote down vote up
def addCallbacks(self):
        """
        Add callbacks that will clear all marker information on the timeline 
        every time a new file is created or a file is opened. It also adds 
        callback to determine if the markers are sliding.
        """
        # after new scene
        self.newID = OpenMaya.MSceneMessage.addCallback(
            OpenMaya.MSceneMessage.kAfterNew, 
            self.readFromCurrentScene
        )
        
        # after open scene
        self.openID = OpenMaya.MSceneMessage.addCallback(
            OpenMaya.MSceneMessage.kAfterOpen, 
            self.readFromCurrentScene
        )

        # timeline press callbacks
        cmds.timeControl(
            utils.getMayaTimeline(), 
            edit=True, 
            pressCommand=self.pressCommand,
            releaseCommand=self.releaseCommand,
        ) 
Example #3
Source File: ui.py    From maya-timeline-marker with GNU General Public License v3.0 6 votes vote down vote up
def removeCallbacks(self):
        """
        Remove Callbacks.
        """
        # remove api callbacks
        for id_ in [self.newID, self.openID]:
            if not id_:
                continue
                
            OpenMaya.MMessage.removeCallback(id_)

        # remove timeline callbacks
        cmds.timeControl(
            utils.getMayaTimeline(), 
            edit=True, 
            pressCommand="", 
            releaseCommand=""
        )
        
    # ------------------------------------------------------------------------ 
Example #4
Source File: capture.py    From maya-capture with MIT License 6 votes vote down vote up
def parse_active_scene():
    """Parse active scene for arguments for capture()

    *Resolution taken from render settings.

    """

    time_control = mel.eval("$gPlayBackSlider = $gPlayBackSlider")

    return {
        "start_frame": cmds.playbackOptions(minTime=True, query=True),
        "end_frame": cmds.playbackOptions(maxTime=True, query=True),
        "width": cmds.getAttr("defaultResolution.width"),
        "height": cmds.getAttr("defaultResolution.height"),
        "compression": cmds.optionVar(query="playblastCompression"),
        "filename": (cmds.optionVar(query="playblastFile")
                     if cmds.optionVar(query="playblastSaveToFile") else None),
        "format": cmds.optionVar(query="playblastFormat"),
        "off_screen": (True if cmds.optionVar(query="playblastOffscreen")
                       else False),
        "show_ornaments": (True if cmds.optionVar(query="playblastShowOrnaments")
                       else False),
        "quality": cmds.optionVar(query="playblastQuality"),
        "sound": cmds.timeControl(time_control, q=True, sound=True) or None
    } 
Example #5
Source File: ml_utilities.py    From ml_tools with MIT License 6 votes vote down vote up
def frameRange(start=None, end=None):
    '''
    Returns the frame range based on the highlighted timeslider,
    or otherwise the playback range.
    '''

    if not start and not end:
        gPlayBackSlider = mm.eval('$temp=$gPlayBackSlider')
        if mc.timeControl(gPlayBackSlider, query=True, rangeVisible=True):
            frameRange = mc.timeControl(gPlayBackSlider, query=True, rangeArray=True)
            start = frameRange[0]
            end = frameRange[1]-1
        else:
            start = mc.playbackOptions(query=True, min=True)
            end = mc.playbackOptions(query=True, max=True)

    return start,end 
Example #6
Source File: ui.py    From maya-timeline-marker with GNU General Public License v3.0 5 votes vote down vote up
def pressCommand(self, *args):
        """
        Press callback on the timeline, this callback registers the current
        selected frames, if the user settings determine that the frame range
        is not important ( no automated shifting of markers ), no range will 
        be stored.
        """
        # variable
        timeline = utils.getMayaTimeline()

        # restore sound scrub
        cmds.timeControl(timeline, edit=True, beginScrub=True)

        # get visible range
        rangeVisible = cmds.timeControl(
            timeline,
            q=True, 
            rangeVisible=True
        )
        
        # check if range needs to be stored
        if not rangeVisible or not self.menu.moveA.isChecked():
            return

        # save range
        self._range = utils.getTimelineRange() 
Example #7
Source File: utils.py    From maya-timeline-marker with GNU General Public License v3.0 5 votes vote down vote up
def getTimelineRange():
    """
    Read the current timeline selection and convert it into a range list.

    :return: Frame range of timeline selection
    :rtype: list
    """
    r = cmds.timeControl(getMayaTimeline(), query=True, ra=True )
    return range(int(r[0]), int(r[1]))

    
# ---------------------------------------------------------------------------- 
Example #8
Source File: maya_warpper.py    From pipeline with MIT License 5 votes vote down vote up
def qeury_active_sound_node():
    aPlayBackSliderPython = mel.eval('$tmpVar=$gPlayBackSlider')
    sound = cmds.timeControl(aPlayBackSliderPython, q=1, s=1)
    if sound:
        return sound
    else:
        return None 
Example #9
Source File: maya_warpper.py    From pipeline with MIT License 5 votes vote down vote up
def playback_selection_range():
    aPlayBackSliderPython = mel.eval('$tmpVar=$gPlayBackSlider')
    time_selection = cmds.timeControl( aPlayBackSliderPython, q=True,rng=True )[1:-1]
    start = round(float(time_selection.split(":")[0]))
    end = round(float(time_selection.split(":")[1]))
    
    if start+1 == end:
        return None
    else:
        return [start, end] 
Example #10
Source File: ml_copyAnim.py    From ml_tools with MIT License 5 votes vote down vote up
def _getStartAndEnd():
    '''
    Only return start and end if frame range is highlighted. Otherwise use all available animation.
    '''

    gPlayBackSlider = mm.eval('$temp=$gPlayBackSlider')
    if mc.timeControl(gPlayBackSlider, query=True, rangeVisible=True):
        start, end = mc.timeControl(gPlayBackSlider, query=True, rangeArray=True)
        return start, end-1
    return None, None 
Example #11
Source File: ml_utilities.py    From ml_tools with MIT License 5 votes vote down vote up
def selectedFrameRange(self):
        '''
        Sets the keySelection time to the selected frame range, returns false if frame range not selected.
        '''

        gPlayBackSlider = mm.eval('$temp=$gPlayBackSlider')
        if mc.timeControl(gPlayBackSlider, query=True, rangeVisible=True):
            self._timeRangeStart, self._timeRangeEnd = mc.timeControl(gPlayBackSlider, query=True, rangeArray=True)
            return True
        return False 
Example #12
Source File: lib.py    From maya-capture-gui with MIT License 5 votes vote down vote up
def get_time_slider_range(highlighted=True,
                          withinHighlighted=True,
                          highlightedOnly=False):
    """Return the time range from Maya's time slider.

    Arguments:
        highlighted (bool): When True if will return a selected frame range
            (if there's any selection of more than one frame!) otherwise it
            will return min and max playback time.
        withinHighlighted (bool): By default Maya returns the highlighted range
            end as a plus one value. When this is True this will be fixed by
            removing one from the last number.

    Returns:
        list: List of two floats of start and end frame numbers.

    """
    if highlighted is True:
        gPlaybackSlider = mel.eval("global string $gPlayBackSlider; "
                                   "$gPlayBackSlider = $gPlayBackSlider;")
        if cmds.timeControl(gPlaybackSlider, query=True, rangeVisible=True):
            highlightedRange = cmds.timeControl(gPlaybackSlider,
                                                query=True,
                                                rangeArray=True)
            if withinHighlighted:
                highlightedRange[-1] -= 1
            return highlightedRange
    if not highlightedOnly:
        return [cmds.playbackOptions(query=True, minTime=True),
                cmds.playbackOptions(query=True, maxTime=True)]