Exemplo n.º 1
0
def main(selectedChannels=True, transformsOnly=False):
    '''
    Resets selected channels in the channel box to default, or if nothing's
    selected, resets all keyable channels to default.
    '''
    gChannelBoxName = mm.eval('$temp=$gChannelBoxName')
    
    sel = mc.ls(sl=True)
    if not sel:
        return
    
    chans = None
    if selectedChannels:
        chans = mc.channelBox(gChannelBoxName, query=True, sma=True)
    
    testList = ['translateX','translateY','translateZ','rotateX','rotateY','rotateZ','scaleX','scaleY','scaleZ',
                'tx','ty','yz','rx','ry','rz','sx','sy','sz']
    for obj in sel:
        attrs = chans
        if not chans:
            attrs = mc.listAttr(obj, keyable=True, unlocked=True)
        if transformsOnly:
            attrs = [x for x in attrs if x in testList]
        if attrs:
            for attr in attrs:
                try:
                    default = mc.attributeQuery(attr, listDefault=True, node=obj)[0]
                    mc.setAttr(obj+'.'+attr, default)
                except StandardError:
                    pass
                
    utl.deselectChannels()
Exemplo n.º 2
0
def main(selectedChannels=True, transformsOnly=False, excludeChannels=None):
    '''
    Resets selected channels in the channel box to default, or if nothing's
    selected, resets all keyable channels to default.
    '''
    gChannelBoxName = mm.eval('$temp=$gChannelBoxName')

    sel = mc.ls(sl=True)
    if not sel:
        return

    if excludeChannels and not isinstance(excludeChannels, (list, tuple)):
        excludeChannels = [excludeChannels]

    chans = None
    if selectedChannels:
        chans = mc.channelBox(gChannelBoxName, query=True, sma=True)

    testList = [
        'translateX', 'translateY', 'translateZ', 'rotateX', 'rotateY',
        'rotateZ', 'scaleX', 'scaleY', 'scaleZ', 'tx', 'ty', 'yz', 'rx', 'ry',
        'rz', 'sx', 'sy', 'sz'
    ]
    for obj in sel:
        attrs = chans
        if not chans:
            attrs = mc.listAttr(obj, keyable=True, unlocked=True)
            if excludeChannels:
                attrs = [x for x in attrs if x not in excludeChannels]
        if transformsOnly:
            attrs = [x for x in attrs if x in testList]
        if attrs:
            for attr in attrs:
                try:
                    default = mc.attributeQuery(attr,
                                                listDefault=True,
                                                node=obj)[0]
                    mc.setAttr(obj + '.' + attr, default)
                except StandardError:
                    pass

    utl.deselectChannels()
Exemplo n.º 3
0
def deleteKey(deleteSubFrames=False,
              selectedKeys=False,
              selectedChannels=False,
              visibleInGraphEditor=False,
              currentFrame=False):
    '''
    The main function arguments:
    
        selectedKeys:           Delete the keys selected in the graph editor
        selectedChannels:       Delete all the keys on selected channels
        visibleInGraphEditor:   Only delete keys that are visible in the graph editor
        currentFrame:           Delete the keys on the current frame
        deleteSubFrames:        Delete sub-frame keys surrounding the current frame
    '''

    sel = mc.ls(sl=True)
    if not sel:
        return

    channels = list()

    if selectedKeys and mc.keyframe(query=True, selected=True):
        #if selected keys (and keys are selected) just cut them
        mc.cutKey(includeUpperBound=False, sl=True, clear=True)
        return

    chanBoxChan = utl.getSelectedChannels()
    if selectedChannels and chanBoxChan:
        #if channel box (and channels are selected)
        curves = list()
        for obj in sel:
            for chan in chanBoxChan:
                temp = mc.listConnections('.'.join((obj, chan)),
                                          source=True,
                                          destination=False,
                                          type='animCurve')
                if temp:
                    curves.append(temp[0])
        if curves:
            mc.cutKey(curves, includeUpperBound=False, clear=True)
            utl.deselectChannels()
            return

    #past this point the options accumulate

    args = list()
    #animCurves = list()
    if visibleInGraphEditor and 'graphEditor1' in mc.getPanel(
            visiblePanels=True):
        #if visible in graph editor and graph editor is open
        graphVis = mc.selectionConnection('graphEditor1FromOutliner',
                                          query=True,
                                          obj=True)
        if graphVis:
            #animCurves = mc.keyframe(graphVis, query=True, name=True)
            args.append(mc.keyframe(graphVis, query=True, name=True))

    kwargs = {'includeUpperBound': False, 'clear': True}
    if currentFrame:
        if not args:
            args = sel
        time = (mc.currentTime(query=True))
        #include sub-frames in the time
        if deleteSubFrames and time % 1 == 0 and -9999 < time < 9999:
            kwargs['time'] = (time - 0.5, time + 0.5)
        else:
            kwargs['time'] = (time, )

    if not args and (selectedKeys or selectedChannels or visibleInGraphEditor
                     or currentFrame):
        #if there were any arguments, but tool hasn't found any curves, don't do anything
        return

    mc.cutKey(*args, **kwargs)
Exemplo n.º 4
0
def deleteKey(deleteSubFrames=False, selectedKeys=False, selectedChannels=False, visibleInGraphEditor=False, currentFrame=False):
    '''
    The main function arguments:
    
        selectedKeys:           Delete the keys selected in the graph editor
        selectedChannels:       Delete all the keys on selected channels
        visibleInGraphEditor:   Only delete keys that are visible in the graph editor
        currentFrame:           Delete the keys on the current frame
        deleteSubFrames:        Delete sub-frame keys surrounding the current frame
    '''
    
    sel = mc.ls(sl=True)
    if not sel:
        return

    channels = list()
    
    if selectedKeys and mc.keyframe(query=True, selected=True):
        #if selected keys (and keys are selected) just cut them
        mc.cutKey(includeUpperBound=False, sl=True, clear=True)
        return
    
    chanBoxChan = utl.getSelectedChannels()
    if selectedChannels and chanBoxChan:
        #if channel box (and channels are selected)
        curves = list()
        for obj in sel:
            for chan in chanBoxChan:
                temp = mc.listConnections('.'.join((obj,chan)), source=True, destination=False, type='animCurve')
                if temp:
                    curves.append(temp[0])
        if curves:
            mc.cutKey(curves, includeUpperBound=False, clear=True)
            utl.deselectChannels()
            return
    
    #past this point the options accumulate
    
    args = list()
    #animCurves = list()
    if visibleInGraphEditor and 'graphEditor1' in mc.getPanel(visiblePanels=True):
        #if visible in graph editor and graph editor is open
        graphVis = mc.selectionConnection('graphEditor1FromOutliner', query=True, obj=True)
        if graphVis:
            #animCurves = mc.keyframe(graphVis, query=True, name=True)
            args.append(mc.keyframe(graphVis, query=True, name=True))
    
    kwargs = {'includeUpperBound':False, 'clear':True}
    if currentFrame:
        if not args:
            args = sel
        time = (mc.currentTime(query=True))
        #include sub-frames in the time
        if deleteSubFrames and time % 1 == 0 and -9999 < time < 9999:
            kwargs['time'] = (time-0.5,time+0.5)
        else:
            kwargs['time'] = (time,)
    
    if not args and (selectedKeys or selectedChannels or visibleInGraphEditor or currentFrame):
        #if there were any arguments, but tool hasn't found any curves, don't do anything
        return
    
    mc.cutKey(*args, **kwargs)
Exemplo n.º 5
0
def setKey(deleteSubFrames=False, insert=False, selectedChannels=False, visibleInGraphEditor=False, keyKeyed=False, keyShapes=False):
    '''
    The main function arguments:
    
        deleteSubFrames:        Delete sub-frame keys surrounding the current frame
        insert:                 Insert key (preserve tangents)
        selectedChannels:       Only key channels that are selected in the Channel Box
        visibleInGraphEditor:   Only key curves visible in Graph Editor
        keyKeyed:               Only set keys on channels that are already keyed
        keyShapes:              Set keyframes on shapes as well as transforms
    '''
    
    sel = mc.ls(sl=True)
    if not sel:
        return

    channels = list()
    
    doInsert = False
    
    if selectedChannels:
        chanBoxChan = utl.getSelectedChannels()
        if chanBoxChan:
            for obj in sel:
                for attr in chanBoxChan:
                    #shapes don't work here? because the channel doesn't exist on the selected object.
                    if mc.attributeQuery(attr, node=obj, exists=True):
                        channels.append('.'.join((obj,attr)))
    
    if channels:
        #this is an interface thing, I like to deselect channels if channels were selected
        utl.deselectChannels()
        
    if visibleInGraphEditor and not channels:
        #then visible in graph editor
        
        #first check if graph editor open
        if 'graphEditor1' in mc.getPanel(visiblePanels=True):
            graphVis = mc.selectionConnection('graphEditor1FromOutliner', query=True, obj=True)
            if graphVis:
                curves = mc.keyframe(graphVis, query=True, name=True)
                if curves:
                    for c in curves:
                        chan = utl.getChannelFromAnimCurve(c)
                        if chan:
                            channels.append(chan)
                    if channels:
                        doInsert = insert
                
    if keyKeyed and not channels:
        #otherwise try keyed channels.
        curves = mc.keyframe(sel, query=True, name=True)
        if curves:
            for c in curves:
                chan = utl.getChannelFromAnimCurve(c)
                if chan:
                    channels.append(chan)
            if channels:
                doInsert = insert
    
    
    if not channels:
        #otherwise just all the selected nodes, flatten the keyable channels.
        for each in sel:
            if doInsert!=insert and mc.keyframe(each, query=True, eval=True):
                #if there's keyframe values, we can can still insert
                doInsert=insert
                
            attrs = mc.listAttr(each, keyable=True, settable=True)
            if attrs:
                channels.extend(['.'.join((each,attr)) for attr in attrs])
                
    
    if not channels:
        OpenMaya.MGlobal.displayWarning('No channels specified.')
        return
    
    #if the user has middle-mouse dragged, we don't want to insert
    #test this by comparing the current attribute value with the evaluated animation curve
    #also check if there's n
    if doInsert:
        for each in channels:
            curveValue = mc.keyframe(each, query=True, eval=True)
            if not curveValue:
                doInsert=False
                break
            if round(mc.getAttr(each),3) != round(curveValue[0],3):
                doInsert=False
                break
        
    
    #this is a special arg, which creates keys on the attributes determined so far
    mc.setKeyframe(channels, insert=doInsert, shape=keyShapes)
    
    #remove nearby sub-frames
    #this breaks at higher frame ranges because maya doesn't keep enough digits
    #this value is also different for different frame rates
    time = mc.currentTime(query=True)
    if deleteSubFrames and time % 1 == 0 and -9999 < time < 9999:
        #the distance that keys can be is independent of frame rate, so we have to convert based on the frame rate.
        tol = getFrameRate()/6000.0
        mc.cutKey(channels, time=(time+tol,time+0.5))
        mc.cutKey(channels, time=(time-0.5,time-tol))
Exemplo n.º 6
0
def setKey(deleteSubFrames=False,
           insert=False,
           selectedChannels=False,
           visibleInGraphEditor=False,
           keyKeyed=False,
           keyShapes=False):
    '''
    The main function arguments:
    
        deleteSubFrames:        Delete sub-frame keys surrounding the current frame
        insert:                 Insert key (preserve tangents)
        selectedChannels:       Only key channels that are selected in the Channel Box
        visibleInGraphEditor:   Only key curves visible in Graph Editor
        keyKeyed:               Only set keys on channels that are already keyed
        keyShapes:              Set keyframes on shapes as well as transforms
    '''

    sel = mc.ls(sl=True)
    if not sel:
        return

    channels = list()

    doInsert = False

    if selectedChannels:
        chanBoxChan = utl.getSelectedChannels()
        if chanBoxChan:
            for obj in sel:
                for attr in chanBoxChan:
                    #shapes don't work here? because the channel doesn't exist on the selected object.
                    if mc.attributeQuery(attr, node=obj, exists=True):
                        channels.append('.'.join((obj, attr)))

    if channels:
        #this is an interface thing, I like to deselect channels if channels were selected
        utl.deselectChannels()

    if visibleInGraphEditor and not channels:
        #then visible in graph editor

        #first check if graph editor open
        if 'graphEditor1' in mc.getPanel(visiblePanels=True):
            graphVis = mc.selectionConnection('graphEditor1FromOutliner',
                                              query=True,
                                              obj=True)
            if graphVis:
                curves = mc.keyframe(graphVis, query=True, name=True)
                if curves:
                    for c in curves:
                        chan = utl.getChannelFromAnimCurve(c)
                        if chan:
                            channels.append(chan)
                    if channels:
                        doInsert = insert

    if keyKeyed and not channels:
        #otherwise try keyed channels.
        curves = mc.keyframe(sel, query=True, name=True)
        if curves:
            for c in curves:
                chan = utl.getChannelFromAnimCurve(c)
                if chan:
                    channels.append(chan)
            if channels:
                doInsert = insert

    if not channels:
        #otherwise just all the selected nodes, flatten the keyable channels.
        for each in sel:
            if doInsert != insert and mc.keyframe(each, query=True, eval=True):
                #if there's keyframe values, we can can still insert
                doInsert = insert

            attrs = mc.listAttr(each, keyable=True, settable=True)
            if attrs:
                channels.extend(['.'.join((each, attr)) for attr in attrs])

    if not channels:
        OpenMaya.MGlobal.displayWarning('No channels specified.')
        return

    #if the user has middle-mouse dragged, we don't want to insert
    #test this by comparing the current attribute value with the evaluated animation curve
    #also check if there's n
    if doInsert:
        for each in channels:
            curveValue = mc.keyframe(each, query=True, eval=True)
            if not curveValue:
                doInsert = False
                break
            if round(mc.getAttr(each), 3) != round(curveValue[0], 3):
                doInsert = False
                break

    #this is a special arg, which creates keys on the attributes determined so far
    mc.setKeyframe(channels, insert=doInsert, shape=keyShapes)

    #remove nearby sub-frames
    #this breaks at higher frame ranges because maya doesn't keep enough digits
    #this value is also different for different frame rates
    time = mc.currentTime(query=True)
    if deleteSubFrames and time % 1 == 0 and -9999 < time < 9999:
        #the distance that keys can be is independent of frame rate, so we have to convert based on the frame rate.
        tol = getFrameRate() / 6000.0
        mc.cutKey(channels, time=(time + tol, time + 0.5))
        mc.cutKey(channels, time=(time - 0.5, time - tol))