def textures(self): """return the textures on the maya File""" textures = [] pat = re.compile('(:?".ftn" -type "string" ")(?P<Path>.+)"') search = pat.search print "in textures", self.path if not self.exists: return [] matches = (search(line) for line in file(self.path, "rb")) refs = [match.group("Path") for match in matches if match] for r in refs: r = tfl.textureFile(r) if r in textures: continue textures.append(r) pat = re.compile('(:?"fileTextureName".+[\n]?[\t]*" -type \\\\"string\\\\" \\\\")(?P<Path>.+)\\\\""') search = pat.search matches = (search(line) for line in file(self.path, "rb")) refs = [match.group("Path") for match in matches if match] for r in refs: r = tfl.textureFile(r) if r in textures: continue textures.append(r) return textures
def moveToFolder(self, textures, folderPath): """ Move the textures to a folder """ for n in textures: if n.type == 'aiImage': attr = "filename" else: attr = "ftn" f = tfl.textureFile( n.attr( attr ).v ) newFile = tfl.textureFile( folderPath + '/' + f.fullName ) if f.exists: newFile = f.copy( folderPath ) n.attr( attr ).v = newFile.path
def setRes(self, newRes, path): tex = tfl.textureFile(path) if newRes == "LOW": return tex.toLow().path elif newRes == "MID": return tex.toMid().path elif newRes == "HIGH": return tex.toHigh().path
def missingFiles(self): """return what frames are missing in the frame range""" missingFils = [] for a in range( self.start, self.end ): a = tfl.textureFile( self.dirPath + self.name + '.' + str(a).zfill(self.padding) + '.' + self.extension ) if not a.exists: missingFils.append( a ) return missingFils
def createVersions(self, textures): """docstring for createVersions""" for n in textures: if n.type == 'aiImage': attr = "filename" else: attr = "ftn" f = tfl.textureFile( n.attr( attr ).v ) f.createVersions()
def fillTextures(self): """add textures from file""" color = [QtGui.QColor( "green" ), QtGui.QColor( "red" )] if self.inMaya: textures = self.manager.textures else: textures = self.fil.textures self.textures_tw.setRowCount( len( textures ) ) for i,t in enumerate(textures): if self.inMaya: if t.type == 'aiImage': attr = "filename" else: attr = "ftn" f = tfl.textureFile( t.attr( attr ).v ) else: f = t #NAME item = QtGui.QTableWidgetItem( f.basename ) item.setCheckState(QtCore.Qt.Unchecked ) item.setData(32, t ) self.textures_tw.setItem( i, 0, item ) #SIZE if not f.exists: item = QtGui.QTableWidgetItem( "0 MB" ) else: item = QtGui.QTableWidgetItem( "%0.2f MB" %f.size ) self.textures_tw.setItem( i, 1, item ) #HASTX item = QtGui.QTableWidgetItem( '' ) colVal = 1 if f.hasTx: if f.exists and f.exists: if f.toTx().isOlderThan(f): colVal = 1 else: colVal = 0 else: colVal = 1 if uiH.USEPYQT: item.setBackgroundColor( color[ colVal ]) else: item.setBackground( color[ colVal ] ) self.textures_tw.setItem( i, 2, item ) #PATH item = QtGui.QTableWidgetItem( f.path ) if f.exists: colVal = 0 else: colVal = 1 if uiH.USEPYQT: item.setBackgroundColor( color[ colVal ]) else: item.setBackground( color[ colVal ] ) self.textures_tw.setItem( i, 3, item )
def createTx(self, textures): """create tx version""" for n in textures: if n.type == 'aiImage': attr = "filename" else: attr = "ftn" f = tfl.textureFile( n.attr( attr ).v ) if not f.exists: continue f.makeTx( True )
def toHigh(self, textures): """docstring for toHigh""" for n in textures: if n.type == 'aiImage': attr = "filename" else: attr = "ftn" f = tfl.textureFile( n.attr( attr ).v ) if f.hasHigh: toPng = f.toHigh() n.attr( attr ).v = toPng.path
def xgenFiles(self): """return xgen files inside maya file""" pat = re.compile('(:?"fileTextureName".+[\n]?[\t]*" -type \\\\"string\\\\" \\\\")(?P<Path>.+)\\\\""') search = pat.search matches = (search(line) for line in file(self.path, "rb")) refs = [match.group("Path") for match in matches if match] for r in refs: r = tfl.textureFile(r) if r in textures: continue textures.append(r)
def renameTexture(self, texture, newName): """docstring for renameTextures""" if texture.type == 'aiImage': attr = "filename" else: attr = "ftn" f = tfl.textureFile( texture.attr( attr ).v ) f.rename( newName + f.extension ) texture.attr( attr ).v = f.path if f.hasTx(): txVer = f.toTx() txVer.rename( newName + txVer.extension )
def toLow(self, textures): """docstring for toLow""" for n in textures: if n.type == 'aiImage': attr = "filename" else: attr = "ftn" f = tfl.textureFile( n.attr( attr ).v ) if not f.hasLow: low = f.makeLow() low.makeTx() toPng = f.toLow() n.attr( attr ).v = toPng.path
def copyTextures(self, newPathFile, BasePath, finalBasePath): """docstring for copyTextures""" for t in newPathFile.textures: origTexture = tfl.textureFile(t.path.replace(BasePath, finalBasePath)) if not t.exists: continue if origTexture.exists: if not origTexture.isOlderThan(t): continue print "copiando ", t.path, origTexture.path t.copy(origTexture.path) # AUTO CREATE TX TODO! origTexture.makeTx(True)
def toPng(self, textures ): """ convert and change path to toPng """ for n in textures: if n.type == 'aiImage': attr = "filename" else: attr = "ftn" f = tfl.textureFile( n.attr( attr ).v ) if f.hasPng: toPng = f.toPng() n.attr( attr ).v = toPng.path
def toMid(self, textures): """docstring for toMid""" for n in textures: if n.type == 'aiImage': attr = "filename" else: attr = "ftn" f = tfl.textureFile( n.attr( attr ).v ) if not f.hasMid: mid = f.makeMid() mid.makeTx() toPng = f.toMid() n.attr( attr ).v = toPng.path
def toTx(self, textures, autoCreate = True): """ convert and change path to toTx """ for n in textures: if n.type == 'aiImage': attr = "filename" else: attr = "ftn" f = tfl.textureFile( n.attr( attr ).v ) if not f.exists: continue if not f.hasTx: f.makeTx( True ) toTx = f.toTx() n.attr( attr ).v = toTx.path
def renameTextures(self): """rename selected Textures""" textures = self.getSelected() for t in textures: if t.type == 'aiImage': attr = "filename" else: attr = "ftn" f = tfl.textureFile( t.attr( attr ).v ) result = mc.promptDialog( title = 'Rename Texture ' + f.name, message = 'Enter New Name:', button = ['OK', 'Cancel','Stop'], defaultButton = 'OK', tx = f.name, cancelButton = 'Cancel', dismissString = 'Cancel') if result == 'OK': newName = mc.promptDialog(query=True, text=True) self.manager.renameTexture( t, newName ) elif result == 'Stop': return self.fillTextures()
def fillTextures(self): """ fill the tw with the textures of the scene """ color = [QtGui.QColor( "green" ), QtGui.QColor( "red" )] textures = self.manager.textures if not textures: return self.textures_tw.clearContents() self.textures_tw.setRowCount( len( textures ) ) for i,t in enumerate(textures): if t.type == 'aiImage': attr = "filename" else: attr = "ftn" f = tfl.textureFile( t.attr( attr ).v ) #NAME item = QtGui.QTableWidgetItem( t.name ) item.setCheckState(QtCore.Qt.Unchecked ) item.setData(32, t ) self.textures_tw.setItem( i, 0, item ) #SIZE if not f.exists: item = QtGui.QTableWidgetItem( "0 MB" ) else: if f.hasUdim: item = QtGui.QTableWidgetItem( "UDIM") else: item = QtGui.QTableWidgetItem( "%0.2f MB" %f.size ) self.textures_tw.setItem( i, 1, item ) #HASTX item = QtGui.QTableWidgetItem( '' ) if f.exists: if not f.hasUdim: if f.hasTx: if f.toTx().isOlderThan(f): colVal = 1 else: colVal = 0 else: colVal = 1 else: colVal = 1 else: colVal = 1 if uiH.USEPYQT: item.setBackgroundColor( color[ colVal ]) else: item.setBackground( color[ colVal ] ) self.textures_tw.setItem( i, 2, item ) #PATH item = QtGui.QTableWidgetItem( f.path ) if f.exists: colVal = 0 else: colVal = 1 if uiH.USEPYQT: item.setBackgroundColor( color[ colVal ]) else: item.setBackground( color[ colVal ] ) self.textures_tw.setItem( i, 3, item )
def textures(self): """return the textures of the asset""" return [ tfl.textureFile( self.texturesPath + a ) for a in os.listdir( self.texturesPath ) if os.path.isfile( self.texturesPath + a ) ]
def previewImagePath(self): """docstring for previewImagePath""" return tfl.textureFile( self.finalPath.path.replace( '.ma', '.png' ) )
def makeTxForTexture(self, texture, serverPath, localPath ): newTextFile = tfl.textureFile( texture.path.replace( serverPath, localPath ) ) newTextFile.makeTx()
def files(self): """return all the files in the sequence""" pa = os.path.join( self.dirPath, '%s.*%s' % ( self.name, self.extension ) ) fils = sorted(glob( pa )) return [ tfl.textureFile( a ) for a in fils ]