Ejemplo n.º 1
0
def setAttributeState(lock=None, hide=None):

    sel = mc.ls(sl=True)
    if not sel:
        OpenMaya.MGlobal.displayWarning('Please make a selection.')
        return

    channels = utl.getSelectedChannels()
    doAll = not bool(channels)

    kwargs = dict()

    for obj in sel:
        attrs = channels[:]
        #we unhide first, so hidden attributes can get unlocked.
        if hide is False and doAll:
            attrs = ['tx','ty','tz','rx','ry','rz','sx','sy','sz','v']
            ud = mc.listAttr(obj, userDefined=True)
            if ud:
                attrs+=ud
                
        elif doAll:
            attrs = mc.listAttr(obj, keyable=True)
        
        if lock is not None:
            kwargs['lock'] = lock
        if hide is not None:
            kwargs['keyable'] = not hide

        if attrs:
            for attr in attrs:
                try:
                    mc.setAttr(obj+'.'+attr, **kwargs)
                except StandardError: pass
Ejemplo n.º 2
0
def setAttributeState(lock=None, hide=None):

    sel = mc.ls(sl=True)
    if not sel:
        OpenMaya.MGlobal.displayWarning('Please make a selection.')
        return

    channels = utl.getSelectedChannels()
    doAll = not bool(channels)

    kwargs = dict()

    for obj in sel:
        attrs = channels[:]
        #we unhide first, so hidden attributes can get unlocked.
        if hide is False and doAll:
            attrs = ['tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz', 'v']
            ud = mc.listAttr(obj, userDefined=True)
            if ud:
                attrs += ud

        elif doAll:
            attrs = mc.listAttr(obj, keyable=True)

        if lock is not None:
            kwargs['lock'] = lock
        if hide is not None:
            kwargs['keyable'] = not hide

        if attrs:
            for attr in attrs:
                try:
                    mc.setAttr(obj + '.' + attr, **kwargs)
                except StandardError:
                    pass
Ejemplo n.º 3
0
def channelBox(*args):

    shortNames = utl.getSelectedChannels()
    if not shortNames:
        return
    sel = mc.ls(sl=True)
    channels = [mc.attributeQuery(x, longName=True, node=sel[-1]) for x in shortNames]
    filterChannels(channels)
Ejemplo n.º 4
0
def channelBox(*args):

    shortNames = utl.getSelectedChannels()
    if not shortNames:
        return
    sel = mc.ls(sl=True)
    channels = [
        mc.attributeQuery(x, longName=True, node=sel[-1]) for x in shortNames
    ]
    filterChannels(channels)
Ejemplo n.º 5
0
def channelBox(*args):
    
    channels = utl.getSelectedChannels()
    if not channels:
        return
    
    sel = mc.ls(sl=True)
    clear()
    for each in sel:
        for c in channels:
            if mc.attributeQuery(c, node=each, exists=True):
                mc.selectionConnection('graphEditor1FromOutliner', edit=True, select=each+'.'+c)
Ejemplo n.º 6
0
def channelBox(*args):

    channels = utl.getSelectedChannels()
    if not channels:
        return

    sel = mc.ls(sl=True)
    clear()
    for each in sel:
        for c in channels:
            if mc.attributeQuery(c, node=each, exists=True):
                mc.selectionConnection('graphEditor1FromOutliner',
                                       edit=True,
                                       select=each + '.' + c)
Ejemplo n.º 7
0
def setAttributeState(lock=None, hide=None):

    sel = mc.ls(sl=True)
    if not sel:
        OpenMaya.MGlobal.displayWarning('Please make a selection.')
        return

    channels = utl.getSelectedChannels()
    doAll = not bool(channels)

    kwargs = dict()

    for obj in sel:
        attrs = channels[:]
        #we unhide first, so hidden attributes can get unlocked.
        if hide is False and doAll:
            attrs = ['tx','ty','tz','rx','ry','rz','sx','sy','sz','v']
            ud = mc.listAttr(obj, userDefined=True)
            if ud:
                attrs+=ud

        elif doAll:
            attrs = mc.listAttr(obj, keyable=True)

        if lock is not None:
            kwargs['lock'] = lock
        if hide is not None:
            kwargs['keyable'] = not hide

        if attrs:
            for attr in attrs:
                try:
                    mc.setAttr(obj+'.'+attr, **kwargs)
                except StandardError: pass

#      ______________________
# - -/__ Revision History __/- - - - - - - - - - - - - - - - - - - - - - - -
#
# Revision 1: 2011-10-08 : First publish.
#
# Revision 2: 2014-03-01 : adding category
#
# Revision 3: 2018-02-17 : Updating license to MIT.
Ejemplo n.º 8
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)
Ejemplo n.º 9
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)
Ejemplo n.º 10
0
def switchSpace(nodes=None, toSpace=None, switchRange=False, bakeOnOnes=False):
    
    if not toSpace:
        return
    
    sel = None
    if not nodes:
        nodes = mc.ls(sl=True)
        sel = nodes
        
    if switchRange:
        start, end = utl.frameRange()
    
    #need to support this eventually for controls which have multiple space attributes.
    selChan = utl.getSelectedChannels()
    
    controls = list()
    attributes = list()
    locators = list()
    values = list()
    for node in nodes:
        ssData = getSpaceSwitchData(node)
        if not ssData:
            continue
        if selChan and selChan[0] in ssData.keys():
            ssAttr = selChan[0]
        else:
            #silly, but take the shortest one, as that's usually default
            ssAttr = min(ssData.keys(), key=len)
        
        if isinstance(toSpace, basestring):
            for i, e in enumerate(ssData[ssAttr]['enumValues']):
                if e.lower() == toSpace.lower():
                    value=i
                    break
        elif isinstance(value, (float, int)):
            value = toSpace
        else:
            print 'Space value not valid:',toSpace
            continue
        
        controls.append(node)
        attributes.append(ssAttr)
        locators.append(mc.spaceLocator(name='TEMP#')[0])
        values.append(value)
    
    if not values:
        return
    
    if switchRange:
        utl.matchBake(controls, locators)
        
        for ctrl, attr, value in zip(controls, attributes, values):
            if mc.keyframe(ctrl+'.'+attr, query=True, name=True):
                mc.cutKey(ctrl+'.'+attr, time=(start,end))
                mc.setKeyframe(ctrl+'.'+attr, value=value, time=(start,end))
            else:
                mc.setAttr(ctrl+'.'+attr, value)
        
        utl.matchBake(locators, controls)
    
    else:
        for ctrl, attr, value, loc in zip(controls, attributes, values, locators):
            mc.delete(mc.parentConstraint(ctrl, loc))
            utl.setAnimValue(ctrl+'.'+attr, value)
            snap(ctrl, loc)
            
    mc.delete(locators)
    if sel:
        mc.select(sel)
Ejemplo n.º 11
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))
Ejemplo n.º 12
0
def switchSpace(nodes=None, toSpace=None, switchRange=False, bakeOnOnes=False):

    if not toSpace:
        return

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

    if switchRange:
        start, end = utl.frameRange()

    #need to support this eventually for controls which have multiple space attributes.
    selChan = utl.getSelectedChannels()

    controls = []
    attributes = []
    locators = []
    values = []
    for node in nodes:

        ssData = getSpaceSwitchData(node)
        if not ssData:
            continue
        if selChan and selChan[0] in ssData.keys():
            ssAttr = selChan[0]
        else:
            #silly, but take the shortest one, as that's usually default
            ssAttr = min(ssData.keys(), key=len)

        if isinstance(toSpace, basestring):
            for i, e in enumerate(ssData[ssAttr]['enumValues']):
                if e.lower() == toSpace.lower():
                    value=i
                    break
        elif isinstance(value, (float, int)):
            value = toSpace
        else:
            print 'Space value not valid:',toSpace
            continue
        currentValue = mc.getAttr(node+'.'+ssAttr)

        if currentValue == value:
            print '{} space already set to {}, skipping'.format(node, toSpace)
            continue

        locator = mc.spaceLocator(name='TEMP#')[0]
        snap(locator, node)

        #need to test flipped before and after switch
        preFlipped = hasFlippedParent(node)

        mc.setAttr(node+'.'+ssAttr, value)
        postFlipped = hasFlippedParent(node)

        mc.setAttr(node+'.'+ssAttr, currentValue)

        #flip locator if we're going to or from a mirrored space
        if preFlipped != postFlipped:
            mc.setAttr(locator+'.rotateX', mc.getAttr(locator+'.rotateX') + 180)

        controls.append(node)
        attributes.append(ssAttr)
        locators.append(locator)
        values.append(value)

    if not values:
        return

    if switchRange:
        utl.matchBake(controls, locators, maintainOffset=True)

        for ctrl, attr, value in zip(controls, attributes, values):
            if mc.keyframe(ctrl+'.'+attr, query=True, name=True):
                mc.cutKey(ctrl+'.'+attr, time=(start,end))
                mc.setKeyframe(ctrl+'.'+attr, value=value, time=(start,end))
            else:
                mc.setAttr(ctrl+'.'+attr, value)

        utl.matchBake(locators, controls)

    else:
        for ctrl, attr, value, loc in zip(controls, attributes, values, locators):
            utl.setAnimValue(ctrl+'.'+attr, value)
            snap(ctrl, loc)

    mc.delete(locators)
    if sel:
        mc.select(sel)
Ejemplo n.º 13
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))
Ejemplo n.º 14
0
def switchSpace(nodes=None, toSpace=None, switchRange=False, bakeOnOnes=False):
    
    if not toSpace:
        return
    
    sel = None
    if not nodes:
        nodes = mc.ls(sl=True)
        sel = nodes
        
    if switchRange:
        start, end = utl.frameRange()
    
    #need to support this eventually for controls which have multiple space attributes.
    selChan = utl.getSelectedChannels()
    
    controls = list()
    attributes = list()
    locators = list()
    values = list()
    for node in nodes:
        ssData = getSpaceSwitchData(node)
        if not ssData:
            continue
        if selChan and selChan[0] in ssData.keys():
            ssAttr = selChan[0]
        else:
            #silly, but take the shortest one, as that's usually default
            ssAttr = min(ssData.keys(), key=len)
        
        if isinstance(toSpace, basestring):
            for i, e in enumerate(ssData[ssAttr]['enumValues']):
                if e.lower() == toSpace.lower():
                    value=i
                    break
        elif isinstance(value, (float, int)):
            value = toSpace
        else:
            print 'Space value not valid:',toSpace
            continue
        
        controls.append(node)
        attributes.append(ssAttr)
        locators.append(mc.spaceLocator(name='TEMP#')[0])
        values.append(value)
    
    if not values:
        return
    
    if switchRange:
        utl.matchBake(controls, locators)
        
        for ctrl, attr, value in zip(controls, attributes, values):
            if mc.keyframe(ctrl+'.'+attr, query=True, name=True):
                mc.cutKey(ctrl+'.'+attr, time=(start,end))
                mc.setKeyframe(ctrl+'.'+attr, value=value, time=(start,end))
            else:
                mc.setAttr(ctrl+'.'+attr, value)
        
        utl.matchBake(locators, controls)
    
    else:
        for ctrl, attr, value, loc in zip(controls, attributes, values, locators):
            mc.delete(mc.parentConstraint(ctrl, loc))
            utl.setAnimValue(ctrl+'.'+attr, value)
            snap(ctrl, loc)
            
    mc.delete(locators)
    if sel:
        mc.select(sel)