예제 #1
0
    def load(self, objects = None, namespaces = None, **kwargs):
        """
        :type objects:
        :type namespaces: list[str]
        :type kwargs:
        """
        validNodes = []
        dstObjects = objects
        srcObjects = self.objects()
        matches = mutils.matchNames(srcObjects, dstObjects=dstObjects, dstNamespaces=namespaces)
        for srcNode, dstNode in matches:
            if '*' in dstNode.name():
                validNodes.append(dstNode.name())
            else:
                dstNode.stripFirstPipe()
                try:
                    dstNode = dstNode.toShortName()
                except mutils.NoObjectFoundError as msg:
                    logger.debug(msg)
                    continue
                except mutils.MoreThanOneObjectFoundError as msg:
                    logger.debug(msg)

                validNodes.append(dstNode.name())

        if validNodes:
            maya.cmds.select(validNodes, **kwargs)
        else:
            raise mutils.NoMatchFoundError('No objects match when loading data')
예제 #2
0
    def load(self, objects=None, namespaces=None, **kwargs):
        """
        :type objects:
        :type namespaces: list[str]
        :type kwargs:
        """
        validNodes = []
        dstObjects = objects
        srcObjects = self.objects()

        matches = mutils.matchNames(srcObjects,
                                    dstObjects=dstObjects,
                                    dstNamespaces=namespaces)

        for srcNode, dstNode in matches:
            # Support for wild cards eg: ['*_control'].
            if "*" in dstNode.name():
                validNodes.append(dstNode.name())
            else:
                # Remove the first pipe in-case the object has a parent.
                dstNode.stripFirstPipe()

                # Try to get the short name. Much faster than the long
                # name when selecting objects.
                try:
                    dstNode = dstNode.toShortName()

                except mutils.NoObjectFoundError, msg:
                    logger.debug(msg)
                    continue

                except mutils.MoreThanOneObjectFoundError, msg:
                    logger.debug(msg)

                validNodes.append(dstNode.name())
예제 #3
0
    def readMayaPath(self, path):
        """
        :type path: str
        """
        if not os.path.exists(path):
            return
        with open(path, 'r') as f:
            lines = f.readlines()
        curve = None
        srcObjects = {}
        for i, line in enumerate(lines):
            if line.startswith('createNode animCurve'):
                curve = line.split('"')[1]
            elif curve and '.fullname' in line:
                try:
                    name, attr = line.split('"')[5].split('.')
                except IndexError:
                    name, attr = lines[i + 1].split('"')[1].split('.')

                srcObjects.setdefault(name, {})
                srcObjects[name][attr] = curve
                curve = None

        matches = mutils.matchNames(srcObjects=srcObjects.keys(),
                                    dstObjects=self.objects().keys())
        for srcNode, dstNode in matches:
            for attr in srcObjects[srcNode.name()]:
                srcName = srcNode.name()
                dstName = dstNode.name()
                curve = srcObjects[srcName][attr]
                self.setAttrCurve(name=dstName, attr=attr, curve=curve)
예제 #4
0
파일: selectionset.py 프로젝트: jonntd/mira
    def load(self, objects = None, namespaces = None, **kwargs):
        """
        :type objects:
        :type namespaces: list[str]
        :type kwargs:
        """
        validNodes = []
        dstObjects = objects
        srcObjects = self.objects()
        matches = mutils.matchNames(srcObjects, dstObjects=dstObjects, dstNamespaces=namespaces)
        for srcNode, dstNode in matches:
            if '*' in dstNode.name():
                validNodes.append(dstNode.name())
            else:
                dstNode.stripFirstPipe()
                try:
                    dstNode = dstNode.toShortName()
                except mutils.NoObjectFoundError as msg:
                    logger.debug(msg)
                    continue
                except mutils.MoreThanOneObjectFoundError as msg:
                    logger.debug(msg)

                validNodes.append(dstNode.name())

        if validNodes:
            maya.cmds.select(validNodes, **kwargs)
        else:
            raise mutils.NoMatchFoundError('No objects match when loading data')
예제 #5
0
    def matchObjects(
        self,
        objects=None,
        namespaces=None,
        selection=False,
        callback=None
    ):
        """
        :type objects: list[str]
        :type namespaces: list[str]
        :type selection: bool
        :type callback: func
        :rtype: list[str]
        """
        results = {}
        srcObjects = self.objects().keys()

        matches = mutils.matchNames(
            srcObjects=srcObjects,
            dstObjects=objects,
            dstNamespaces=namespaces,
        )

        for srcNode, dstNode in matches:
            dstObj = dstNode.name()
            mirrorAxis = self.mirrorAxis(srcNode.name())
            callback(srcNode.name(), dstObj, mirrorAxis)

        return results
예제 #6
0
    def readMayaPath(self, path):
        """
        :type path: str
        """
        if not os.path.exists(path):
            return
        with open(path, 'r') as f:
            lines = f.readlines()
        curve = None
        srcObjects = {}
        for i, line in enumerate(lines):
            if line.startswith('createNode animCurve'):
                curve = line.split('"')[1]
            elif curve and '.fullname' in line:
                try:
                    name, attr = line.split('"')[5].split('.')
                except IndexError:
                    name, attr = lines[i + 1].split('"')[1].split('.')

                srcObjects.setdefault(name, {})
                srcObjects[name][attr] = curve
                curve = None

        matches = mutils.matchNames(srcObjects=srcObjects.keys(), dstObjects=self.objects().keys())
        for srcNode, dstNode in matches:
            for attr in srcObjects[srcNode.name()]:
                srcName = srcNode.name()
                dstName = dstNode.name()
                curve = srcObjects[srcName][attr]
                self.setAttrCurve(name=dstName, attr=attr, curve=curve)
예제 #7
0
    def load(
        self,
        objects=None,
        namespaces=None,
        option=None,
        animation=True,
        time=None
    ):
        """
        :type objects: list[str]
        :type namespaces: list[str]
        :type option: mirrorOptions
        :type animation: bool
        :type time: None or list[int]
        """
        results = {}
        foundObject = False
        srcObjects = self.objects().keys()

        if option is None:
            option = MirrorOption.Swap

        matches = mutils.matchNames(
            srcObjects=srcObjects,
            dstObjects=objects,
            dstNamespaces=namespaces,
        )

        for srcNode, dstNode in matches:
            dstObj = dstNode.name()
            dstObj2 = self.mirrorObject(dstObj) or dstObj

            if dstObj2 not in results:
                results[dstObj] = dstObj2

                mirrorAxis = self.mirrorAxis(srcNode.name())
                dstObjExists = maya.cmds.objExists(dstObj)
                dstObj2Exists = maya.cmds.objExists(dstObj2)

                if dstObjExists and dstObj2Exists:
                    foundObject = True
                    if animation:
                        self.transferAnimation(dstObj, dstObj2, mirrorAxis=mirrorAxis, option=option, time=time)
                    else:
                        self.transferStatic(dstObj, dstObj2, mirrorAxis=mirrorAxis, option=option)
                else:
                    if not dstObjExists:
                        msg = "Cannot find destination object {0}"
                        msg = msg.format(dstObj)
                        logger.debug(msg)

                    if not dstObj2Exists:
                        msg = "Cannot find mirrored destination object {0}"
                        msg = msg.format(dstObj2)
                        logger.debug(msg)

        if not foundObject:
            raise mutils.NoMatchFoundError("No objects match when loading data")
    def matchNames(self, expectedResult, srcObjects = None, dstObjects = None, dstNamespaces = None):
        """
        """
        result = []
        for srcNode, dstNode in mutils.matchNames(srcObjects, dstObjects=dstObjects, dstNamespaces=dstNamespaces):
            result.append((srcNode.name(), dstNode.name()))

        if result != expectedResult:
            raise Exception('Result does not match the expected result: %s != %s' % (str(result), expectedResult))
예제 #9
0
    def matchNames(self, expectedResult, srcObjects = None, dstObjects = None, dstNamespaces = None):
        """
        """
        result = []
        for srcNode, dstNode in mutils.matchNames(srcObjects, dstObjects=dstObjects, dstNamespaces=dstNamespaces):
            result.append((srcNode.name(), dstNode.name()))

        if result != expectedResult:
            raise Exception('Result does not match the expected result: %s != %s' % (str(result), expectedResult))
예제 #10
0
    def load(self, objects = None, namespaces = None, attrs = None, startFrame = None, sourceTime = None, option = None, connect = False, mirrorTable = None, currentTime = None):
        """
        :type objects: list[str]
        :type namespaces: list[str]
        :type startFrame: int
        :type sourceTime: (int, int)
        :type attrs: list[str]
        :type option: PasteOption
        :type currentTime: bool
        """
        connect = bool(connect)
        if option is None or option == PasteOption.ReplaceAll:
            option = PasteOption.ReplaceCompletely
        logger.debug('Animation.load(objects=%s, option=%s, namespaces=%s, srcTime=%s, currentTime=%s)' % (len(objects),
         str(option),
         str(namespaces),
         str(sourceTime),
         str(currentTime)))
        if currentTime and startFrame is None:
            startFrame = int(maya.cmds.currentTime(query=True))
        try:
            srcCurves = self.open()
            srcObjects = self.objects().keys()
            srcTime = self.srcTime(sourceTime, srcCurves)
            dstTime = self.dstTime(srcTime, startFrame)
            if mirrorTable:
                self.setMirrorTable(mirrorTable)
            maya.cmds.flushUndo()
            maya.cmds.undoInfo(openChunk=True)
            matches = list(mutils.matchNames(srcObjects=srcObjects, dstObjects=objects, dstNamespaces=namespaces))
            if not matches:
                raise mutils.NoMatchFoundError('No objects match when loading data')
            if option != PasteOption.ReplaceCompletely:
                insertSourceKeyframe(srcCurves, srcTime)
            for srcNode, dstNode in matches:
                dstNode.stripFirstPipe()
                for attr in self.attrs(srcNode.name()):
                    if attrs is not None and attr not in attrs:
                        continue
                    dstAttr = mutils.Attribute(dstNode.name(), attr)
                    srcCurve = self.attrCurve(srcNode.name(), attr, withNamespace=True)
                    if not dstAttr.exists():
                        logger.debug('Skipping attribute: The destination attribute "%s.%s" does not exist!' % (dstAttr.name(), dstAttr.attr()))
                        continue
                    if srcCurve is None:
                        type_ = self.attrType(srcNode.name(), attr)
                        value = self.attrValue(srcNode.name(), attr)
                        srcAttr = mutils.Attribute(dstNode.name(), attr, type=type_, value=value)
                        self.setStaticKey(srcAttr, dstAttr, dstTime, option)
                    else:
                        self.setAnimationKey(srcCurve, dstAttr, time=dstTime, option=option, source=srcTime, connect=connect)

        finally:
            self.close()
            maya.cmds.undoInfo(closeChunk=True)
예제 #11
0
    def updateCache(self,
                    objects=None,
                    namespaces=None,
                    dstAttrs=None,
                    ignoreConnected=False,
                    onlyConnected=False,
                    cache=True,
                    mirrorTable=None,
                    search=None,
                    replace=None):
        """
        :type objects: list[str]
        :type namespaces: list[str]
        :type dstAttrs: list[str]
        """
        cacheKey = str(objects) + str(namespaces) + str(dstAttrs) + \
                   str(ignoreConnected) + str(maya.cmds.currentTime(query=True))

        if self._cacheKey != cacheKey or not cache:
            self._cache = []
            self._cacheKey = cacheKey

            dstObjects = objects
            srcObjects = self.objects()
            usingNamespaces = not objects and namespaces

            if mirrorTable:
                self.setMirrorTable(mirrorTable)

            matches = mutils.matchNames(
                srcObjects,
                dstObjects=dstObjects,
                dstNamespaces=namespaces,
                search=search,
                replace=replace,
            )

            for srcNode, dstNode in matches:

                self.cacheNode(
                    srcNode,
                    dstNode,
                    dstAttrs=dstAttrs,
                    onlyConnected=onlyConnected,
                    ignoreConnected=ignoreConnected,
                    usingNamespaces=usingNamespaces,
                )

        if not self.cache():
            text = "No objects match when loading data. " \
                   "Turn on debug mode to see more details."

            raise mutils.NoMatchFoundError(text)
예제 #12
0
    def load(self, objects=None, namespaces=None, **kwargs):
        """
        Load/Select the transfer objects to the given objects or namespaces.
        
        :type objects: list[str] or None
        :type namespaces: list[str] or None
        :type kwargs:
        """
        validNodes = []
        dstObjects = objects
        srcObjects = self.objects()

        self.validate(namespaces=namespaces)

        matches = mutils.matchNames(
                srcObjects,
                dstObjects=dstObjects,
                dstNamespaces=namespaces
        )

        for srcNode, dstNode in matches:
            # Support for wild cards eg: ['*_control'].
            if "*" in dstNode.name():
                validNodes.append(dstNode.name())
            else:
                # Remove the first pipe in-case the object has a parent.
                dstNode.stripFirstPipe()

                # Try to get the short name. Much faster than the long
                # name when selecting objects.
                try:
                    dstNode = dstNode.toShortName()

                except mutils.NoObjectFoundError as error:
                    logger.debug(error)
                    continue

                except mutils.MoreThanOneObjectFoundError as error:
                    logger.debug(error)

                validNodes.append(dstNode.name())

        if validNodes:
            maya.cmds.select(validNodes, **kwargs)

            # Return the focus to the Maya window
            maya.cmds.setFocus("MayaWindow")
        else:
            text = "No objects match when loading data. " \
                   "Turn on debug mode to see more details."

            raise mutils.NoMatchFoundError(text)
예제 #13
0
    def load(self, objects=None, namespaces=None, **kwargs):
        """
        Load/Select the transfer objects to the given objects or namespaces.
        
        :type objects: list[str] or None
        :type namespaces: list[str] or None
        :type kwargs:
        """
        validNodes = []
        dstObjects = objects
        srcObjects = self.objects()

        self.validate(namespaces=namespaces)

        matches = mutils.matchNames(
                srcObjects,
                dstObjects=dstObjects,
                dstNamespaces=namespaces
        )

        for srcNode, dstNode in matches:
            # Support for wild cards eg: ['*_control'].
            if "*" in dstNode.name():
                validNodes.append(dstNode.name())
            else:
                # Remove the first pipe in-case the object has a parent.
                dstNode.stripFirstPipe()

                # Try to get the short name. Much faster than the long
                # name when selecting objects.
                try:
                    dstNode = dstNode.toShortName()

                except mutils.NoObjectFoundError as error:
                    logger.debug(error)
                    continue

                except mutils.MoreThanOneObjectFoundError as error:
                    logger.debug(error)

                validNodes.append(dstNode.name())

        if validNodes:
            maya.cmds.select(validNodes, **kwargs)

            # Return the focus to the Maya window
            maya.cmds.setFocus("MayaWindow")
        else:
            text = "No objects match when loading data. " \
                   "Turn on debug mode to see more details."

            raise mutils.NoMatchFoundError(text)
예제 #14
0
 def _readLegacy(self, mayaPath):
     """
     We only need to read the maya ascii file if it's legacy data.
     
     :type mayaPath: str
     """
     srcObjects = animCurvesFromMayaAscii(mayaPath)
     matches = mutils.matchNames(srcObjects=srcObjects.keys(), dstObjects=self.objects().keys())
     for srcNode, dstNode in matches:
         for attr in srcObjects[srcNode.name()]:
             srcName = srcNode.name()
             dstName = dstNode.name()
             curve = srcObjects[srcName][attr]
             self.setAnimCurve(name=dstName, attr=attr, curve=curve)
예제 #15
0
파일: animation.py 프로젝트: jonntd/mira
 def _readLegacy(self, mayaPath):
     """
     We only need to read the maya ascii file if it's legacy data.
     
     :type mayaPath: str
     """
     srcObjects = animCurvesFromMayaAscii(mayaPath)
     matches = mutils.matchNames(srcObjects=srcObjects.keys(),
                                 dstObjects=self.objects().keys())
     for srcNode, dstNode in matches:
         for attr in srcObjects[srcNode.name()]:
             srcName = srcNode.name()
             dstName = dstNode.name()
             curve = srcObjects[srcName][attr]
             self.setAnimCurve(name=dstName, attr=attr, curve=curve)
예제 #16
0
    def matchObjects(self, objects = None, namespaces = None, selection = False, callback = None):
        """
        :type objects: list[str]
        :type namespaces: list[str]
        :type selection: bool
        :type callback: func
        :rtype: list[str]
        """
        results = {}
        srcObjects = self.objects().keys()
        matches = mutils.matchNames(srcObjects=srcObjects, dstObjects=objects, dstNamespaces=namespaces)
        for srcNode, dstNode in matches:
            dstObj = dstNode.name()
            mirrorAxis = self.mirrorAxis(srcNode.name())
            callback(srcNode.name(), dstObj, mirrorAxis)

        return results
예제 #17
0
    def updateCache(self, objects = None, namespaces = None, dstAttrs = None, ignoreConnected = False, onlyConnected = False, cache = True, mirrorTable = None, search = None, replace = None):
        """
        :type objects: list[str]
        :type namespaces: list[str]
        :type dstAttrs: list[str]
        """
        cacheKey = str(objects) + str(namespaces) + str(dstAttrs) + str(ignoreConnected) + str(maya.cmds.currentTime(query=True))
        if self._cacheKey != cacheKey or not cache:
            self._cache = []
            self._cacheKey = cacheKey
            dstObjects = objects
            srcObjects = self.objects()
            usingNamespaces = not objects and namespaces
            if mirrorTable:
                self.setMirrorTable(mirrorTable)
            matches = mutils.matchNames(srcObjects, dstObjects=dstObjects, dstNamespaces=namespaces, search=search, replace=replace)
            for srcNode, dstNode in matches:
                self.cacheNode(srcNode, dstNode, dstAttrs=dstAttrs, onlyConnected=onlyConnected, ignoreConnected=ignoreConnected, usingNamespaces=usingNamespaces)

        if not self.cache():
            raise mutils.NoMatchFoundError('No objects match when loading data')
예제 #18
0
    def matchObjects(
        self,
        objects=None,
        namespaces=None,
    ):
        """
        :type objects: list[str]
        :type namespaces: list[str]
        :rtype: list[str]
        """
        srcObjects = self.objects().keys()

        matches = mutils.matchNames(
            srcObjects=srcObjects,
            dstObjects=objects,
            dstNamespaces=namespaces,
        )

        for srcNode, dstNode in matches:
            dstName = dstNode.name()
            mirrorAxis = self.mirrorAxis(srcNode.name())
            yield srcNode.name(), dstName, mirrorAxis
예제 #19
0
    def matchObjects(
        self,
        objects=None,
        namespaces=None,
    ):
        """
        :type objects: list[str]
        :type namespaces: list[str]
        :rtype: list[str]
        """
        srcObjects = self.objects().keys()

        matches = mutils.matchNames(
            srcObjects=srcObjects,
            dstObjects=objects,
            dstNamespaces=namespaces,
        )

        for srcNode, dstNode in matches:
            dstName = dstNode.name()
            mirrorAxis = self.mirrorAxis(srcNode.name())
            yield srcNode.name(), dstName, mirrorAxis
예제 #20
0
    def load(self, objects = None, namespaces = None, option = None, animation = True, time = None):
        """
        :type objects: list[str]
        :type namespaces: list[str]
        :type option: mirrorOptions
        """
        results = {}
        foundObject = False
        srcObjects = self.objects().keys()
        if option is None:
            option = MirrorOption.Swap
        matches = mutils.matchNames(srcObjects=srcObjects, dstObjects=objects, dstNamespaces=namespaces)
        for srcNode, dstNode in matches:
            dstObj = dstNode.name()
            dstObj2 = self.mirrorObject(dstObj) or dstObj
            if dstObj2 not in results:
                results[dstObj] = dstObj2
                mirrorAxis = self.mirrorAxis(srcNode.name())
                dstObjExists = maya.cmds.objExists(dstObj)
                dstObj2Exists = maya.cmds.objExists(dstObj2)
                if dstObjExists and dstObj2Exists:
                    foundObject = True
                    if animation:
                        self.transferAnimation(dstObj, dstObj2, mirrorAxis=mirrorAxis, option=option, time=time)
                    else:
                        self.transferStatic(dstObj, dstObj2, mirrorAxis=mirrorAxis, option=option)
                else:
                    if not dstObjExists:
                        msg = 'Cannot find destination object {0}'
                        msg = msg.format(dstObj)
                        logger.debug(msg)
                    if not dstObj2Exists:
                        msg = 'Cannot find mirrored destination object {0}'
                        msg = msg.format(dstObj2)
                        logger.debug(msg)

        if not foundObject:
            raise mutils.NoMatchFoundError('No objects match when loading data')
예제 #21
0
    def load(self,
             objects=None,
             namespaces=None,
             attrs=None,
             startFrame=None,
             sourceTime=None,
             option=None,
             connect=False,
             mirrorTable=None,
             currentTime=None):
        """
        Load the animation data to the given objects or namespaces.

        :type objects: list[str]
        :type namespaces: list[str]
        :type startFrame: int
        :type sourceTime: (int, int)
        :type attrs: list[str]
        :type option: PasteOption
        :type connect: bool
        :type mirrorTable: mutils.MirrorTable
        :type currentTime: bool or None
        """
        connect = bool(connect)  # Make false if connect is None

        if option is None or option == PasteOption.ReplaceAll:
            option = PasteOption.ReplaceCompletely

        objects = objects or []

        logger.debug(
            "Animation.load(objects=%s, option=%s, namespaces=%s, srcTime=%s, currentTime=%s)"
            % (len(objects), str(option), str(namespaces), str(sourceTime),
               str(currentTime)))

        srcObjects = self.objects().keys()

        if mirrorTable:
            self.setMirrorTable(mirrorTable)

        valid = False
        matches = list(
            mutils.matchNames(srcObjects=srcObjects,
                              dstObjects=objects,
                              dstNamespaces=namespaces))

        for srcNode, dstNode in matches:
            if dstNode.exists():
                valid = True
                break

        if not matches or not valid:

            text = "No objects match when loading data. " \
                   "Turn on debug mode to see more details."

            raise mutils.NoMatchFoundError(text)

        # Load the animation data.
        srcCurves = self.open()

        try:
            maya.cmds.flushUndo()
            maya.cmds.undoInfo(openChunk=True)

            if currentTime and startFrame is None:
                startFrame = int(maya.cmds.currentTime(query=True))

            srcTime = findFirstLastKeyframes(srcCurves, sourceTime)
            dstTime = moveTime(srcTime, startFrame)

            if option != PasteOption.ReplaceCompletely:
                insertKeyframe(srcCurves, srcTime)

            for srcNode, dstNode in matches:

                # Remove the first pipe in-case the object has a parent
                dstNode.stripFirstPipe()

                for attr in self.attrs(srcNode.name()):

                    # Filter any attributes if the parameter has been set
                    if attrs is not None and attr not in attrs:
                        continue

                    dstAttr = mutils.Attribute(dstNode.name(), attr)
                    srcCurve = self.animCurve(srcNode.name(),
                                              attr,
                                              withNamespace=True)

                    # Skip if the destination attribute does not exists.
                    if not dstAttr.exists():
                        logger.debug(
                            'Skipping attribute: The destination attribute "%s.%s" does not exist!'
                            % (dstAttr.name(), dstAttr.attr()))
                        continue

                    if srcCurve:
                        dstAttr.setAnimCurve(srcCurve,
                                             time=dstTime,
                                             option=option,
                                             source=srcTime,
                                             connect=connect)
                    else:
                        value = self.attrValue(srcNode.name(), attr)
                        dstAttr.setStaticKeyframe(value, dstTime, option)

        finally:
            self.close()
            maya.cmds.undoInfo(closeChunk=True)

            # Return the focus to the Maya window
            maya.cmds.setFocus("MayaWindow")
예제 #22
0
파일: animation.py 프로젝트: jonntd/mira
    def load(self,
             objects=None,
             namespaces=None,
             attrs=None,
             startFrame=None,
             sourceTime=None,
             option=None,
             connect=False,
             mirrorTable=None,
             currentTime=None):
        """
        Load the animation data to the given objects or namespaces.
        
        :type objects: list[str]
        :type namespaces: list[str]
        :type startFrame: int
        :type sourceTime: (int, int)
        :type attrs: list[str]
        :type option: PasteOption
        :type currentTime: bool
        """
        connect = bool(connect)
        if option is None or option == PasteOption.ReplaceAll:
            option = PasteOption.ReplaceCompletely
        objects = objects or []
        logger.debug(
            'Animation.load(objects=%s, option=%s, namespaces=%s, srcTime=%s, currentTime=%s)'
            % (len(objects), str(option), str(namespaces), str(sourceTime),
               str(currentTime)))
        srcObjects = self.objects().keys()
        if mirrorTable:
            self.setMirrorTable(mirrorTable)
        valid = False
        matches = list(
            mutils.matchNames(srcObjects=srcObjects,
                              dstObjects=objects,
                              dstNamespaces=namespaces))
        for srcNode, dstNode in matches:
            if dstNode.exists():
                valid = True
                break

        if not matches or not valid:
            raise mutils.NoMatchFoundError(
                'No objects match when loading data')
        srcCurves = self.open()
        try:
            maya.cmds.flushUndo()
            maya.cmds.undoInfo(openChunk=True)
            if currentTime and startFrame is None:
                startFrame = int(maya.cmds.currentTime(query=True))
            srcTime = findFirstLastKeyframes(srcCurves, sourceTime)
            dstTime = moveTime(srcTime, startFrame)
            if option != PasteOption.ReplaceCompletely:
                insertKeyframe(srcCurves, srcTime)
            for srcNode, dstNode in matches:
                dstNode.stripFirstPipe()
                for attr in self.attrs(srcNode.name()):
                    if attrs is not None and attr not in attrs:
                        continue
                    dstAttr = mutils.Attribute(dstNode.name(), attr)
                    srcCurve = self.animCurve(srcNode.name(),
                                              attr,
                                              withNamespace=True)
                    if not dstAttr.exists():
                        logger.debug(
                            'Skipping attribute: The destination attribute "%s.%s" does not exist!'
                            % (dstAttr.name(), dstAttr.attr()))
                        continue
                    if srcCurve is None:
                        type_ = self.attrType(srcNode.name(), attr)
                        value = self.attrValue(srcNode.name(), attr)
                        srcAttr = mutils.Attribute(dstNode.name(),
                                                   attr,
                                                   type=type_,
                                                   value=value)
                        self.setStaticKey(srcAttr, dstAttr, dstTime, option)
                    else:
                        self.setAnimationKey(srcCurve,
                                             dstAttr,
                                             time=dstTime,
                                             option=option,
                                             source=srcTime,
                                             connect=connect)

        finally:
            self.close()
            maya.cmds.undoInfo(closeChunk=True)
예제 #23
0
    def updateCache(
        self,
        objects=None,
        namespaces=None,
        attrs=None,
        ignoreConnected=False,
        onlyConnected=False,
        mirrorTable=None,
        batchMode=False,
        clearCache=True,
        searchAndReplace=None,
    ):
        """
        Update the pose cache.
        
        :type objects: list[str] or None 
        :type namespaces: list[str] or None
        :type attrs: list[str] or None
        :type ignoreConnected: bool
        :type onlyConnected: bool
        :type clearCache: bool
        :type batchMode: bool
        :type mirrorTable: mutils.MirrorTable
        :type searchAndReplace: (str, str) or None
        """
        if clearCache or not batchMode or not self._mtime:
            self._mtime = self.mtime()

        mtime = self._mtime

        cacheKey = \
            str(mtime) + \
            str(objects) + \
            str(attrs) + \
            str(namespaces) + \
            str(ignoreConnected) + \
            str(searchAndReplace) + \
            str(maya.cmds.currentTime(query=True))

        if self._cacheKey != cacheKey or clearCache:

            self.validate(namespaces=namespaces)

            self._cache = []
            self._cacheKey = cacheKey

            dstObjects = objects
            srcObjects = self.objects()
            usingNamespaces = not objects and namespaces

            if mirrorTable:
                self.setMirrorTable(mirrorTable)

            search = None
            replace = None
            if searchAndReplace:
                search = searchAndReplace[0]
                replace = searchAndReplace[1]

            matches = mutils.matchNames(
                srcObjects,
                dstObjects=dstObjects,
                dstNamespaces=namespaces,
                search=search,
                replace=replace,
            )

            for srcNode, dstNode in matches:
                self.cacheNode(
                    srcNode,
                    dstNode,
                    attrs=attrs,
                    onlyConnected=onlyConnected,
                    ignoreConnected=ignoreConnected,
                    usingNamespaces=usingNamespaces,
                )

        if not self.cache():
            text = "No objects match when loading data. " \
                   "Turn on debug mode to see more details."

            raise mutils.NoMatchFoundError(text)
예제 #24
0
    def updateCache(
            self,
            objects=None,
            namespaces=None,
            attrs=None,
            ignoreConnected=False,
            onlyConnected=False,
            mirrorTable=None,
            search=None,
            replace=None,
            batchMode=False,
            clearCache=True
    ):
        """
        Update the pose cache.
        
        :type objects: list[str] or None 
        :type namespaces: list[str] or None
        :type attrs: list[str] or None
        :type ignoreConnected: bool
        :type onlyConnected: bool
        :type clearCache: bool
        :type batchMode: bool
        :type mirrorTable: mutils.MirrorTable
        :type search: str or None
        :type replace: str or None
        """
        if clearCache or not batchMode or not self._mtime:
            self._mtime = self.mtime()

        mtime = self._mtime

        cacheKey = \
            str(mtime) + \
            str(objects) + \
            str(attrs) + \
            str(namespaces) + \
            str(ignoreConnected) + \
            str(maya.cmds.currentTime(query=True))

        if self._cacheKey != cacheKey or clearCache:

            self.validate(namespaces=namespaces)

            self._cache = []
            self._cacheKey = cacheKey

            dstObjects = objects
            srcObjects = self.objects()
            usingNamespaces = not objects and namespaces

            if mirrorTable:
                self.setMirrorTable(mirrorTable)

            matches = mutils.matchNames(
                srcObjects,
                dstObjects=dstObjects,
                dstNamespaces=namespaces,
                search=search,
                replace=replace,
            )

            for srcNode, dstNode in matches:
                self.cacheNode(
                    srcNode,
                    dstNode,
                    attrs=attrs,
                    onlyConnected=onlyConnected,
                    ignoreConnected=ignoreConnected,
                    usingNamespaces=usingNamespaces,
                )

        if not self.cache():
            text = "No objects match when loading data. " \
                   "Turn on debug mode to see more details."

            raise mutils.NoMatchFoundError(text)
예제 #25
0
    def load(
            self,
            objects=None,
            namespaces=None,
            attrs=None,
            startFrame=None,
            sourceTime=None,
            option=None,
            connect=False,
            mirrorTable=None,
            currentTime=None
    ):
        """
        Load the animation data to the given objects or namespaces.

        :type objects: list[str]
        :type namespaces: list[str]
        :type startFrame: int
        :type sourceTime: (int, int)
        :type attrs: list[str]
        :type option: PasteOption
        :type connect: bool
        :type mirrorTable: mutils.MirrorTable
        :type currentTime: bool or None
        """
        connect = bool(connect)  # Make false if connect is None

        self.validate(namespaces=namespaces)

        if option is None or option == PasteOption.ReplaceAll:
            option = PasteOption.ReplaceCompletely

        objects = objects or []

        logger.debug("Animation.load(objects=%s, option=%s, namespaces=%s, srcTime=%s, currentTime=%s)" %
                     (len(objects), str(option), str(namespaces), str(sourceTime), str(currentTime)))

        srcObjects = self.objects().keys()

        if mirrorTable:
            self.setMirrorTable(mirrorTable)

        valid = False
        matches = list(mutils.matchNames(srcObjects=srcObjects, dstObjects=objects, dstNamespaces=namespaces))

        for srcNode, dstNode in matches:
            if dstNode.exists():
                valid = True
                break

        if not matches or not valid:

            text = "No objects match when loading data. " \
                   "Turn on debug mode to see more details."

            raise mutils.NoMatchFoundError(text)

        # Load the animation data.
        srcCurves = self.open()

        try:
            maya.cmds.flushUndo()
            maya.cmds.undoInfo(openChunk=True)

            if currentTime and startFrame is None:
                startFrame = int(maya.cmds.currentTime(query=True))

            srcTime = findFirstLastKeyframes(srcCurves, sourceTime)
            dstTime = moveTime(srcTime, startFrame)

            if option != PasteOption.ReplaceCompletely:
                insertKeyframe(srcCurves, srcTime)

            for srcNode, dstNode in matches:

                # Remove the first pipe in-case the object has a parent
                dstNode.stripFirstPipe()

                for attr in self.attrs(srcNode.name()):

                    # Filter any attributes if the parameter has been set
                    if attrs is not None and attr not in attrs:
                        continue

                    dstAttr = mutils.Attribute(dstNode.name(), attr)
                    srcCurve = self.animCurve(srcNode.name(), attr, withNamespace=True)

                    # Skip if the destination attribute does not exists.
                    if not dstAttr.exists():
                        logger.debug('Skipping attribute: The destination attribute "%s.%s" does not exist!' %
                                     (dstAttr.name(), dstAttr.attr()))
                        continue

                    if srcCurve:
                        dstAttr.setAnimCurve(
                            srcCurve,
                            time=dstTime,
                            option=option,
                            source=srcTime,
                            connect=connect
                        )
                    else:
                        value = self.attrValue(srcNode.name(), attr)
                        dstAttr.setStaticKeyframe(value, dstTime, option)

        finally:
            self.close()
            maya.cmds.undoInfo(closeChunk=True)

            # Return the focus to the Maya window
            maya.cmds.setFocus("MayaWindow")
예제 #26
0
    def load(
        self,
        objects=None,
        namespaces=None,
        option=None,
        animation=True,
        time=None
    ):
        """
        :type objects: list[str]
        :type namespaces: list[str]
        :type option: mirrorOptions
        :type animation: bool
        :type time: None or list[int]
        """
        self.validate(namespaces=namespaces)

        results = {}
        foundObject = False
        srcObjects = self.objects().keys()

        if option is None:
            option = MirrorOption.Swap

        matches = mutils.matchNames(
            srcObjects=srcObjects,
            dstObjects=objects,
            dstNamespaces=namespaces,
        )
        logger.debug("*********************")
        logger.debug(("matches = {0}").format(matches))
        # logger.debug()
        for srcNode, dstNode in matches:
            dstObj = dstNode.name()
            logger.debug("KKK disObj name = " + dstObj)
            logger.debug("KKK srcNode.name = " + srcNode.name())
            dstObj2 = self.mirrorObject(dstObj) or dstObj

            if dstObj2 not in results:
                results[dstObj] = dstObj2

                mirrorAxis = self.mirrorAxis(srcNode.name())
                dstObjExists = maya.cmds.objExists(dstObj)
                dstObj2Exists = maya.cmds.objExists(dstObj2)
                logger.debug(("dstObj2 = {0}").format(dstObj2))

                if dstObjExists and dstObj2Exists:
                    foundObject = True
                    if animation:
                        logger.debug("transferAnimation !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
                        self.transferAnimation(dstObj, dstObj2, mirrorAxis=mirrorAxis, option=option, time=time)
                    else:
                        logger.debug("transferStatic !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
                        self.transferStatic(dstObj, dstObj2, mirrorAxis=mirrorAxis, option=option)
                else:
                    if not dstObjExists:
                        msg = "Cannot find destination object {0}"
                        msg = msg.format(dstObj)
                        logger.debug(msg)

                    if not dstObj2Exists:
                        msg = "Cannot find mirrored destination object {0}"
                        msg = msg.format(dstObj2)
                        logger.debug(msg)

        # Return the focus to the Maya window
        maya.cmds.setFocus("MayaWindow")

        if not foundObject:

            text = "No objects match when loading data. " \
                   "Turn on debug mode to see more details."

            raise mutils.NoMatchFoundError(text)
예제 #27
0
    def load(
        self,
        objects=None,
        namespaces=None,
        option=None,
        keysOption=None,
        time=None,
    ):
        """
        Load the mirror table for the given objects.

        :type objects: list[str]
        :type namespaces: list[str]
        :type option: mirrorOptions
        :type keysOption: None or KeysOption.SelectedRange
        :type time: None or list[int]
        """
        if option and not isinstance(option, int):
            if option.lower() == "swap":
                option = 0
            elif option.lower() == "left to right":
                option = 1
            elif option.lower() == "right to left":
                option = 2
            else:
                raise ValueError('Invalid load option=' + str(option))

        self.validate(namespaces=namespaces)

        results = {}
        animation = True
        foundObject = False
        srcObjects = self.objects().keys()

        if option is None:
            option = MirrorOption.Swap

        if keysOption == KeysOption.All:
            time = None
        elif keysOption == KeysOption.SelectedRange:
            time = mutils.selectedFrameRange()

        # Check to make sure that the given time is not a single frame
        if time and time[0] == time[1]:
            time = None
            animation = False

        matches = mutils.matchNames(
            srcObjects=srcObjects,
            dstObjects=objects,
            dstNamespaces=namespaces,
        )

        for srcNode, dstNode in matches:
            dstObj = dstNode.name()
            dstObj2 = self.mirrorObject(dstObj) or dstObj

            if dstObj2 not in results:
                results[dstObj] = dstObj2

                mirrorAxis = self.mirrorAxis(srcNode.name())
                dstObjExists = maya.cmds.objExists(dstObj)
                dstObj2Exists = maya.cmds.objExists(dstObj2)

                if dstObjExists and dstObj2Exists:
                    foundObject = True
                    if animation:
                        self.transferAnimation(dstObj,
                                               dstObj2,
                                               mirrorAxis=mirrorAxis,
                                               option=option,
                                               time=time)
                    else:
                        self.transferStatic(dstObj,
                                            dstObj2,
                                            mirrorAxis=mirrorAxis,
                                            option=option)
                else:
                    if not dstObjExists:
                        msg = "Cannot find destination object {0}"
                        msg = msg.format(dstObj)
                        logger.debug(msg)

                    if not dstObj2Exists:
                        msg = "Cannot find mirrored destination object {0}"
                        msg = msg.format(dstObj2)
                        logger.debug(msg)

        # Return the focus to the Maya window
        maya.cmds.setFocus("MayaWindow")

        if not foundObject:

            text = "No objects match when loading data. " \
                   "Turn on debug mode to see more details."

            raise mutils.NoMatchFoundError(text)
예제 #28
0
    def load(
        self,
        objects=None,
        namespaces=None,
        option=None,
        animation=True,
        time=None
    ):
        """
        :type objects: list[str]
        :type namespaces: list[str]
        :type option: mirrorOptions
        :type animation: bool
        :type time: None or list[int]
        """
        self.validate(namespaces=namespaces)

        results = {}
        foundObject = False
        srcObjects = self.objects().keys()

        if option is None:
            option = MirrorOption.Swap

        matches = mutils.matchNames(
            srcObjects=srcObjects,
            dstObjects=objects,
            dstNamespaces=namespaces,
        )

        for srcNode, dstNode in matches:
            dstObj = dstNode.name()
            dstObj2 = self.mirrorObject(dstObj) or dstObj

            if dstObj2 not in results:
                results[dstObj] = dstObj2

                mirrorAxis = self.mirrorAxis(srcNode.name())
                dstObjExists = maya.cmds.objExists(dstObj)
                dstObj2Exists = maya.cmds.objExists(dstObj2)

                if dstObjExists and dstObj2Exists:
                    foundObject = True
                    if animation:
                        self.transferAnimation(dstObj, dstObj2, mirrorAxis=mirrorAxis, option=option, time=time)
                    else:
                        self.transferStatic(dstObj, dstObj2, mirrorAxis=mirrorAxis, option=option)
                else:
                    if not dstObjExists:
                        msg = "Cannot find destination object {0}"
                        msg = msg.format(dstObj)
                        logger.debug(msg)

                    if not dstObj2Exists:
                        msg = "Cannot find mirrored destination object {0}"
                        msg = msg.format(dstObj2)
                        logger.debug(msg)

        # Return the focus to the Maya window
        maya.cmds.setFocus("MayaWindow")

        if not foundObject:

            text = "No objects match when loading data. " \
                   "Turn on debug mode to see more details."

            raise mutils.NoMatchFoundError(text)