Example #1
0
 def importAssetCache(self, cacheXmlLt, cacheErrorCheck = False):
     """ cacheXmlLt = "R:/data/cache/sq001/sh001/light/char/ben00c_ben/ben00c_ben.xml" """
     if os.path.exists(cacheXmlLt):
         cacheChannels = mc.cacheFile(fileName=cacheXmlLt,q=1,channelName=1)
         cacheGeos = self.getCacheGeos()
         cacheGeoDict, cacheChannelsTmp = {}, []
         for chn in cacheChannels:
             for geo in cacheGeos:
                 baseChn = utils.stripNames(utils.convertName(chn, "texture"))
                 baseGeo = utils.stripNames(utils.stripNames(geo, ":"), "|")
                 if baseChn in baseGeo:
                     cacheGeoDict[chn] = geo
                     cacheChannelsTmp.append(chn)
                     continue
     else:
         utils.msgWin("Error", "File does not exist : %s"%cacheXmlLt, self.silent)
         return False
     if cacheErrorCheck:
         missedChannels = list(set(cacheChannels).difference(set(cacheGeoDict.keys())))
         if len(missedChannels) > 0:
             msg = "Cache geometry missing\n"
             msg += "\n".join(missedChannels)
             utils.msgWin("Error", msg, self.silent)
             return missedChannels
         else:
             return False
     for chNode in self.getCacheNodes():
         mc.delete(chNode)
     for chn in cacheGeoDict.keys():
         deformShp = cacheGeoDict[chn]
         try:
             shpSwitch = mc.deformer(deformShp, type="historySwitch")
         except:
             continue
         shpHist = mc.listHistory(deformShp, pdo=1)
         if shpHist:
             for hist in shpHist:
                 if mc.nodeType(hist) == "tweak":
                     dblList = mc.listAttr("%s.plist"%hist, m= 1)
                     fltList = mc.listAttr("%s.vlist"%hist, m= 1)
                     dbCon, flCon = False, False
                     if dblList:
                         if len(dblList) > 1: dbCon = True
                     if fltList:
                         if len(fltList) > 1: flCon = True
                     if not(dbCon or flCon):
                         mc.delete(hist)
                     break
         conns = mc.listConnections("%s.ip[0].ig"%shpSwitch[0], p=1)
         mc.connectAttr(conns[0], "%s.ug[0]"%shpSwitch[0])
         mc.setAttr("%s.playFromCache"%shpSwitch[0], 1)
         mc.getAttr("%s.op[0]"%shpSwitch[0], sl = 1)
         mc.setAttr("%s.playFromCache"%shpSwitch[0], 0)
         mc.disconnectAttr(conns[0], "%s.ug[0]"%shpSwitch[0])
         switch = mc.rename(shpSwitch[0],'cacheSwitch#')
         mc.setAttr(switch+'.ihi',0)
         cacheNode = mc.cacheFile(f = cacheXmlLt, attachFile = True, ia = '%s.inp[0]'%switch, cnm = chn)
         mc.connectAttr(cacheNode+".inRange", switch + '.playFromCache')
     utils.msgWin("Message", "Cache loaded successfully for %s"%self.namespace, self.silent)
     return True
Example #2
0
 def checkImportErrors(self, silent = True, update = False, refNodes = []):
     errorLog = []
     if self.checkExportErrors():
         errorLog.extend(self.exportErrorLog)
     if not os.path.exists(self.shotCacheXmlAn):
         utils.msgWin("Error", "XML file does not exist : %s"%self.shotCacheXmlAn, True)
         errorLog.append("XML file does not exist : %s"%self.shotCacheXmlAn)
     else:
         self.readXML()
         cacheNotFound = []
         animFldr = os.path.join(self.shotCacheFldr, "anim")
         liteFldr = os.path.join(self.shotCacheFldr, "light")
         if refNodes:
             asts = refNodes
             refRes = "texture"
         else:
             asts = self.assets.keys()
             refRes = "rig"
         for ast in asts:
             if refRes == "texture":
                 astObj = MayaAsset(ast)
                 if astObj.validAsset:
                     scNamespace = astObj.namespace
                     namespace = utils.convertName(scNamespace, "rig", True)
                     topNode = astObj.topGrp
                     if not mc.objExists(topNode):
                         errorLog.append("Missing reference/assets in scene : %s"%topNode)
                         continue
                 else:
                     continue
             else:
                 namespace = self.assets[ast]['namespace']
                 scNamespace = utils.convertName(namespace, "texture", True)
                 topName = self.assets[ast]['name']
                 topNode = "%s:%s"%(scNamespace, topName)
                 if mc.objExists(topNode):
                     try:
                         refNode = mc.referenceQuery(topNode, rfn = True)
                     except:
                         print "Reference has been cut for : %s"%topNode
                         continue
                 else:
                     errorLog.append("Missing reference/asset in scene : %s"%topNode)
                     continue
                 astObj = MayaAsset(refNode)
             if not os.path.exists(astObj.assetPath):
                 errorLog.append("Missing High Asset : %s"%astObj.assetPath)
                 utils.msgWin("Error", "Missing High Asset : %s"%astObj.assetPath, True)
             astType = astObj.assetType
             cacheName = (utils.convertName(topNode, "rig", False)).replace(":", "_")
             cacheFldrAn = os.path.join(animFldr, astType, cacheName)
             cacheFldrLt = os.path.join(liteFldr, astType, cacheName)
             cacheFile = os.path.join(cacheFldrAn, "%s.mc"%cacheName)
             if astObj.getCacheGeos():
                 if not os.path.exists(cacheFile):
                     cacheFile = os.path.join(cacheFldrLt, "%s.mc"%cacheName)
                     if not os.path.exists(cacheFile):
                         print "missing", cacheFile
                         cacheNotFound.append(cacheFile.replace("\\", "/"))
             missedChn = astObj.importAssetCache(cacheFile, True) 
             if missedChn:
                 errorLog.append("Cache Geometry missing for %s"%astObj.namespace)
                 print "\nCache Geometry missing for %s:"%astObj.namespace
                 for chn in missedChn:
                     print "Channel mismatch for %s"%chn
                 print "\n"
         if cacheNotFound:
             errorLog.append("\nThe following animation cache files do not exist:\n")
             utils.msgWin("Error", "\nThe following animation cache files do not exist:\n", True)
             for cchNotF in cacheNotFound:
                 errorLog.append("%s"%cchNotF)
                 utils.msgWin("Error", "%s"%cchNotF, True)
         if os.path.exists(os.path.dirname(self.shotCacheXmlLt)):
             lockedFiles = utils.checkLockedFiles(os.path.dirname(self.shotCacheXmlLt), "mc")
             if lockedFiles:
                 msg = "Following Light cache files are in use. Please close\nallother maya files that might be accessing this cache folder\n"
                 for lckFil in lockedFiles:
                     msg += "%s\n"%lckFil
                 utils.msgWin("Error", msg, True)
                 errorLog.append(msg)
     if update:
         if not os.path.exists(self.shotCacheXmlLt):
             utils.msgWin("Error", "Light XML not found : %s"%self.shotCacheXmlLt, True)
             errorLog.append("Light XML not found : %s"%self.shotCacheXmlLt)
     if errorLog:
         errorLog.append("\nImport Cache Operation Aborted\n")
         self.importErrorLog = errorLog
         utils.msgWin("Cache Scene Errors", "\n".join(errorLog), silent)
         return True
     else:
         return False
Example #3
0
 def getAstCacheFldr(self, shotCacheFldr, typ = "anim"):
     self.astCacheName = utils.convertName(self.topGrp, "rig").replace(':','_')
     animCachePath='%s/%s/%s/%s' %(shotCacheFldr,typ,self.assetType,self.astCacheName)
     return animCachePath