Esempio n. 1
0
def copySingle(source=None,
               destination=None,
               pasteMethod='replace',
               offset=0,
               addToLayer=False,
               rotateOrder=True):
    '''
    Copy animation from a source node and paste it to a destination node
    '''

    start, end = _getStartAndEnd()

    if not source and not destination:
        sel = mc.ls(sl=True)
        if len(sel) != 2:
            OpenMaya.MGlobal.displayWarning('Please select exactly 2 objects.')
            return

        source = sel[0]
        destination = sel[1]

    layer = None
    if addToLayer:
        layer = utl.createAnimLayer(destination, namePrefix='ml_cp')

    copyAnimation(source=source,
                  destination=destination,
                  pasteMethod=pasteMethod,
                  offset=offset,
                  start=start,
                  end=end,
                  layer=layer,
                  rotateOrder=rotateOrder)
Esempio n. 2
0
def copySingle(source=None, destination=None, pasteMethod="replace", offset=0, addToLayer=False):
    """
    Copy animation from a source node and paste it to a destination node
    """

    start, end = _getStartAndEnd()

    if not source and not destination:
        sel = mc.ls(sl=True)

        if len(sel) != 2:
            OpenMaya.MGlobal.displayWarning("Please select exactly 2 objects.")
            return

        source = sel[0]
        destination = sel[1]

    layer = None
    if addToLayer:
        layer = utl.createAnimLayer(destination, namePrefix="ml_cp")

    copyAnimation(
        source=source,
        destination=destination,
        pasteMethod=pasteMethod,
        offset=offset,
        start=start,
        end=end,
        layer=layer,
    )
Esempio n. 3
0
def copySingle(source=None, destination=None, pasteMethod='replace', offset=0, addToLayer=False, rotateOrder=True):
    '''
    Copy animation from a source node and paste it to a destination node
    '''

    start, end = _getStartAndEnd()

    if not source and not destination:
        sel = mc.ls(sl=True)
        if len(sel) < 2:
            OpenMaya.MGlobal.displayWarning('Please select 2 or more objects.')
            return

        source = sel[0]
        destination = sel[1:]

    layer = None
    if addToLayer:
        layer = utl.createAnimLayer(destination, namePrefix='ml_cp')

    copyAnimation(source=source, destination=destination, pasteMethod=pasteMethod, offset=offset, start=start, end=end, layer=layer, rotateOrder=rotateOrder)
Esempio n. 4
0
def copyHierarchy(sourceTop=None,
                  destinationTop=None,
                  pasteMethod='replace',
                  offset=0,
                  addToLayer=False,
                  layerName=None,
                  rotateOrder=True):
    '''
    Copy animation from a source hierarchy and paste it to a destination hierarchy.
    '''
    start, end = _getStartAndEnd()

    if not sourceTop and not destinationTop:
        sel = mc.ls(sl=True)

        if len(sel) != 2:
            OpenMaya.MGlobal.displayWarning('Please select exactly 2 objects.')
            return

        sourceTop = sel[0]
        destinationTop = sel[1]

    #get keyed objects below source
    nodes = mc.listRelatives(sourceTop, pa=True, ad=True) or []
    nodes.append(sourceTop)
    keyed = []

    for node in nodes:
        # this will only return time based keyframes, not driven keys
        if mc.keyframe(node, time=(':', ), query=True, keyframeCount=True):
            keyed.append(node)

    if not keyed:
        return

    #get a list of all nodes under the destination
    allDestNodes = mc.listRelatives(destinationTop, ad=True, pa=True) or []
    allDestNodes.append(destinationTop)

    destNodeMap = {}
    duplicate = []
    for each in allDestNodes:
        name = each.rsplit('|')[-1].rsplit(':')[-1]
        if name in duplicate:
            continue
        if name in destNodeMap.keys():
            duplicate.append(name)
            continue
        destNodeMap[name] = each

    destNS = utl.getNamespace(destinationTop)

    layer = None
    if addToLayer:
        if not layerName:
            layerName = 'copyHierarchy'
        layer = utl.createAnimLayer(name=layerName)

    for node in keyed:
        #strip name
        nodeName = node.rsplit('|')[-1].rsplit(':')[-1]

        if nodeName in duplicate:
            print 'Two or more destination nodes have the same name: ' + destNS + nodeName
            continue
        if nodeName not in destNodeMap.keys():
            print 'Cannot find destination node: ' + destNS + nodeName
            continue

        copyAnimation(source=node,
                      destination=destNodeMap[nodeName],
                      pasteMethod=pasteMethod,
                      offset=offset,
                      start=start,
                      end=end,
                      layer=layer,
                      rotateOrder=rotateOrder)
Esempio n. 5
0
def copyHierarchy(sourceTop=None, destinationTop=None, pasteMethod='replace', offset=0, addToLayer=False, layerName=None, rotateOrder=True):
    '''
    Copy animation from a source hierarchy and paste it to a destination hierarchy.
    '''
    start, end = _getStartAndEnd()

    if not sourceTop and not destinationTop:
        sel = mc.ls(sl=True)

        if len(sel) != 2:
            OpenMaya.MGlobal.displayWarning('Please select exactly 2 objects.')
            return

        sourceTop = sel[0]
        destinationTop = sel[1]

    #get keyed objects below source
    nodes = mc.listRelatives(sourceTop, pa=True, ad=True) or []
    nodes.append(sourceTop)
    keyed = []

    for node in nodes:
        # this will only return time based keyframes, not driven keys
        if mc.keyframe(node, time=(':',), query=True, keyframeCount=True):
            keyed.append(node)

    if not keyed:
        return

    #get a list of all nodes under the destination
    allDestNodes = mc.listRelatives(destinationTop, ad=True, pa=True) or []
    allDestNodes.append(destinationTop)

    destNodeMap = {}
    duplicate = []
    for each in allDestNodes:
        name = each.rsplit('|')[-1].rsplit(':')[-1]
        if name in duplicate:
            continue
        if name in destNodeMap.keys():
            duplicate.append(name)
            continue
        destNodeMap[name] = each

    destNS = utl.getNamespace(destinationTop)

    layer = None
    if addToLayer:
        if not layerName:
            layerName = 'copyHierarchy'
        layer = utl.createAnimLayer(name=layerName)

    for node in keyed:
        #strip name
        nodeName = node.rsplit('|')[-1].rsplit(':')[-1]

        if nodeName in duplicate:
            print 'Two or more destination nodes have the same name: '+destNS+nodeName
            continue
        if nodeName not in destNodeMap.keys():
            print 'Cannot find destination node: '+destNS+nodeName
            continue

        copyAnimation(source=node, destination=destNodeMap[nodeName], pasteMethod=pasteMethod, offset=offset, start=start, end=end, layer=layer, rotateOrder=rotateOrder)
Esempio n. 6
0
def copyHierarchy(sourceTop=None, destinationTop=None, pasteMethod='replace', offset=0, addToLayer=False, layerName=None):
    '''
    Copy animation from a source hierarchy and paste it to a destination hierarchy.
    '''
    start, end = _getStartAndEnd()
    
    if not sourceTop and not destinationTop:
        sel = mc.ls(sl=True)
        
        if len(sel) != 2:
            OpenMaya.MGlobal.displayWarning('Please select exactly 2 objects.')
            return
            
        sourceTop = sel[0]
        destinationTop = sel[1]
    
    #get keyed objects below source
    nodes = mc.listRelatives(sourceTop, pa=True, ad=True)
    if not nodes:
        nodes = list()
    nodes.append(sourceTop)
    keyed = list()
    
    for node in nodes:
        # this will only return time based keyframes, not driven keys
        if mc.keyframe(node, time=(':',), query=True, keyframeCount=True):
            keyed.append(node)

    if not keyed:
        return
    
    #get a list of all nodes under the destination
    destNodes = mc.listRelatives(destinationTop, ad=True)
    if not destNodes:
        destNodes = list()
    destNodes.append(destinationTop)
    
    destNS = utl.getNamespace(destinationTop)
    destNames = [x.rpartition(':')[-1] for x in destNodes]
    
    layer = None
    if addToLayer:
        if not layerName:
            layerName = 'copyHierarchy'
        layer = utl.createAnimLayer(name=layerName)
        
    for node in keyed:
        nodeName = mc.ls(node, shortNames=True)[0]
        
        #strip namespace
        if ':' in nodeName:
            nodeName = nodeName.rpartition(':')[-1]
        
        if nodeName in destNames:
            destNode = mc.ls(destNS+nodeName)
            if not destNode:
                print 'Cannot find destination node: '+destNS+':'+nodeName
                continue
            if len(destNode) > 1:
                print 'Two or more destination nodes have the same name: '+destNS+':'+nodeName
                continue
            
            copyAnimation(source=node, destination=destNode[0], pasteMethod=pasteMethod, offset=offset, start=start, end=end, layer=layer)
Esempio n. 7
0
def copyHierarchy(sourceTop=None,
                  destinationTop=None,
                  pasteMethod='replace',
                  offset=0,
                  addToLayer=False,
                  layerName=None):
    '''
    Copy animation from a source hierarchy and paste it to a destination hierarchy.
    '''
    start, end = _getStartAndEnd()

    if not sourceTop and not destinationTop:
        sel = mc.ls(sl=True)

        if len(sel) != 2:
            OpenMaya.MGlobal.displayWarning('Please select exactly 2 objects.')
            return

        sourceTop = sel[0]
        destinationTop = sel[1]

    #get keyed objects below source
    nodes = mc.listRelatives(sourceTop, pa=True, ad=True)
    if not nodes:
        nodes = list()
    nodes.append(sourceTop)
    keyed = list()

    for node in nodes:
        # this will only return time based keyframes, not driven keys
        if mc.keyframe(node, time=(':', ), query=True, keyframeCount=True):
            keyed.append(node)

    if not keyed:
        return

    #get a list of all nodes under the destination
    destNodes = mc.listRelatives(destinationTop, ad=True)
    if not destNodes:
        destNodes = list()
    destNodes.append(destinationTop)

    destNS = utl.getNamespace(destinationTop)
    destNames = [x.rpartition(':')[-1] for x in destNodes]

    layer = None
    if addToLayer:
        if not layerName:
            layerName = 'copyHierarchy'
        layer = utl.createAnimLayer(name=layerName)

    for node in keyed:
        nodeName = mc.ls(node, shortNames=True)[0]

        #strip namespace
        if ':' in nodeName:
            nodeName = nodeName.rpartition(':')[-1]

        if nodeName in destNames:
            destNode = mc.ls(destNS + nodeName)
            if not destNode:
                print 'Cannot find destination node: ' + destNS + ':' + nodeName
                continue
            if len(destNode) > 1:
                print 'Two or more destination nodes have the same name: ' + destNS + ':' + nodeName
                continue

            copyAnimation(source=node,
                          destination=destNode[0],
                          pasteMethod=pasteMethod,
                          offset=offset,
                          start=start,
                          end=end,
                          layer=layer)