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')
def load(self, objects = None, namespaces = None, option = MirrorOption.Swap, animation = True, time = None): """ @param objects: list[str] @param namespaces: list[str] @param option: mirrorOptions """ srcObjects = self.objects().keys() matches = mutils.matchObjects(srcObjects=srcObjects, dstObjects=objects, dstNamespaces=namespaces) foundObject = False results = {} for srcNode, dstNode in matches: dstObj = dstNode.name() dstObj2 = self.mirrorObject(dstObj) or dstObj if dstObj2 not in results: mirrorAxis = self.mirrorAxis(srcNode.name()) results[dstObj] = dstObj2 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: log.debug('Cannot find destination object %s' % dstObj) if not dstObj2Exists: log.debug('Cannot find mirrored destination object %s' % dstObj2) if not foundObject: raise mutils.NoMatchFoundError('No objects match when loading data')
def updateCache(self, objects=None, namespaces=None, dstAttrs=None, ignoreConnected=False, onlyConnected=False, cache=True, mirrorTable=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) mutils.matchObjects(srcObjects, dstObjects=dstObjects, dstNamespaces=namespaces, callback=self.cacheNode, dstAttrs=dstAttrs, ignoreConnected=ignoreConnected, onlyConnected=onlyConnected, usingNamespaces=usingNamespaces) if not self.cache(): raise mutils.NoMatchFoundError( 'No objects match when loading data')
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 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)
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)
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")
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)
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)
def load(self, objects=None, namespaces=None, start=None, sourceTime=None, attrs=None, currentTime=None, option=Option.ReplaceCompletely, connect=False, mirrorTable=None): """ @type objects: list[str] @type namespaces: list[str] @type start: int @type sourceTime: (int, int) @type attrs: list[str] @type option: Option @type currentTime: bool """ if option == Option.ReplaceAll: option = Option.ReplaceCompletely log.debug( 'Animation.load(objects=%s, option=%s, namespaces=%s, srcTime=%s, currentTime=%s)' % (len(objects), str(option), str(sourceTime), str(namespaces), str(currentTime))) if currentTime and start is None: start = maya.cmds.currentTime(query=True) try: srcCurves = self.open() srcObjects = self.objects().keys() srcTime = self.srcTime(sourceTime, srcCurves) dstTime = self.dstTime(srcTime, start) if mirrorTable: self.setMirrorTable(mirrorTable) maya.cmds.flushUndo() maya.cmds.undoInfo(openChunk=True) matches = mutils.matchObjects(srcObjects=srcObjects, dstObjects=objects, dstNamespaces=namespaces) if not matches: raise mutils.NoMatchFoundError( 'No objects match when loading data') if option != Option.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(): log.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)
except mutils.NoObjectFoundError, msg: logger.debug(msg) continue except mutils.MoreThanOneObjectFoundError, msg: logger.debug(msg) 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) def select(self, objects=None, namespaces=None, **kwargs): """ Convenience method for any classes inheriting SelectionSet. :type objects: str :type namespaces: list[str] :rtype: None """ SelectionSet.load(self, objects=objects, namespaces=namespaces, **kwargs)
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)
try: dstNode = dstNode.toShortName() except mutils.NoObjectFoundError, msg: logger.debug(msg) continue except mutils.MoreThanOneObjectFoundError, 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") def select(self, objects=None, namespaces=None, **kwargs): """ :type objects: :type namespaces: list[str] :type kwargs: """ SelectionSet.load(self, objects=objects, namespaces=namespaces, **kwargs) @mutils.showWaitCursor def save(self, *args, **kwargs): """
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)