def find_latest_outputs(self, shot, task_type='Comp'): """finds the latest outputs of the given task type of the given Shot """ from stalker import Task task = Task.query\ .filter(Task.parent==shot)\ .filter(Task.name==task_type)\ .first() # this part is not very parametric, and depends highly to out # project structure if task: # get the task folder output_path = '%s/Outputs/Main' % task.absolute_path import os import glob import pyseq # check the folder and get the latest output folder version_folders = reversed( sorted( glob.glob( os.path.join(output_path, '*') ) ) ) for version_folder in version_folders: # check if the current version folder has exr files exr_path = ('%s/exr/*.exr' % version_folder).replace('\\', '/') png_path = ('%s/png/*.png' % version_folder).replace('\\', '/') seqs = pyseq.getSequences(exr_path) # and if not go to a previous version # until you check all the version paths if seqs: return 'localhost/%s/%s' % ( os.path.normpath(os.path.split(seqs[0].path())[0]).replace('\\', '/'), seqs[0].format('%h|5B%03s-%03e|5D%t').replace('|', '%') ) else: # also check png sequences png_seqs = pyseq.getSequences(png_path) if png_seqs: print( "%s %s has PNG but no EXR" % (shot.name, version_folder.split('/')[-1]) ) return '' return None
def test_getSequences_is_working_properly_1(self): """testing if getSequences is working properly """ seqs = getSequences('./files/') expected_results = [ '012_vb_110_v001.1-10.png', '012_vb_110_v002.1-10.png', 'a.1-14.tga', 'alpha.txt', 'bnc01_TinkSO_tx_0_ty_0.101-105.tif', 'bnc01_TinkSO_tx_0_ty_1.101-105.tif', 'bnc01_TinkSO_tx_1_ty_0.101-105.tif', 'bnc01_TinkSO_tx_1_ty_1.101-105.tif', 'file.1-2.tif', 'file.info.03.rgb', 'file01_40-43.rgb', 'file02_44-47.rgb', 'file1-4.03.rgb', 'fileA.1-3.jpg', 'fileA.1-3.png', 'file_02.tif', 'z1_001_v1.1-4.png', 'z1_002_v1.1-4.png', 'z1_002_v2.1-4.png', ] for seq, expected_result in zip(seqs, expected_results): self.assertEqual( expected_result, str(seq) )
def test_getSequences_is_working_properly_2(self): """testing if getSequences is working properly """ seqs = getSequences(['fileA.1.rgb', 'fileA.2.rgb', 'fileB.1.rgb']) expected_results = [ 'fileA.1-2.rgb', 'fileB.1.rgb' ] for seq, expected_result in zip(seqs, expected_results): self.assertEqual( expected_result, str(seq) )
def getSequence(self): if type( self.source ) == type([]): self.sequenceList = self.source else : thepath = self.source + '/*' if self.source[-1] != '/' else self.source + '*' self.sequenceList = [ x for x in glob.glob( thepath ) if os.path.isfile( x ) ] print 'seqList : ' , self.sequenceList self.sequenceList.sort() seq = pyseq.getSequences( self.sequenceList ) if len( seq ) > 0 : return seq[0] else : print 'source : ' , self.source return False
def test_getSequences_is_working_properly_3(self): """testing if getSequences is working properly """ seqs = getSequences('./tests/files/bnc*') expected_results = [ 'bnc01_TinkSO_tx_0_ty_0.%04d.tif 101-105', 'bnc01_TinkSO_tx_0_ty_1.%04d.tif 101-105', 'bnc01_TinkSO_tx_1_ty_0.%04d.tif 101-105', 'bnc01_TinkSO_tx_1_ty_1.%04d.tif 101-105', ] for seq, expected_result in zip(seqs, expected_results): self.assertEqual( expected_result, seq.format('%h%p%t %r') )
def getSequence(fileName): """ Find sequences in the parent folder of fileName and return the sequence to which fileName belongs. :param fileName: file path. :return: pyseq.Sequence instance. """ dirName = os.path.dirname(fileName) files = [os.path.join(dirName, f) for f in os.listdir(dirName)] seqs = getSequences(files) for seq in seqs: if seq.contains(fileName): return seq
def reformatText(self, model): if model == 1: doSetUps.mergeSelectCamUI(1) self.selectedNode = nuke.selectedNodes('ContactSheet')[0] _source = nuke.selectedNodes('Read') elif model == 2: self.selectedNode = nuke.selectedNodes('ContactSheet')[0] _source = nuke.selectedNodes('Read') if self.selectedNode: p = nuke.Panel('reformatTextUI') p.addSingleLineInput('scale:', '0.5') p.addButton('Cancel') p.addButton('OK') p.setWidth(10) self.panleResult = p.show() if self.panleResult: option = p.value('scale:') if option: self.createNode(option, 2) myfileName = _source[0]['file'].value() myFiledirName = os.path.dirname(myfileName) getSequences = pyseq.getSequences(myFiledirName)[0] getStartFrame = getSequences[0]._get_filename().split( ".")[1] getLastFrame = getSequences[-1]._get_filename().split( ".")[1] myFileN = myfileName.split("/") dirName = "/".join(myFileN[0:-2]) myDir = dirName + "/check" if not os.path.isdir(myDir): os.makedirs(myDir) WriteFile = myDir + "/check.%04d.png" self.nodeWrite['file'].setValue(WriteFile) nuke.scriptSaveAs( dirName + "/check_%s_(%s-%s).nk" % (myFileN[-3], getStartFrame, getLastFrame)) return 1 else: return ""
def __init__(self, jobdict, dept, shot, direction, category, version): print '\t> %s > %s > %s > %s > %s > core.renders.render_nuke_passes' % (dept, shot, direction, category, version) #lets set up some vars self.jobdict = jobdict self.job = jobdict.keys()[0] self.dept = dept self.shot = shot self.direction = direction self.version = version self.category = category self.renderroot = os.path.join(core.jobsRoot, self.job, 'vfx', self.dept, self.shot, 'plates', self.direction, self.category, self.version) seq_class = pyseq.getSequences(self.renderroot) new = [] for each in seq_class: new.append(each.split(' ')[-1]) self.jobdict[self.job][self.dept]['shots'][shot]['renders'][self.direction][self.category][self.version] = seq_class
def __init__(self, jobdict, dept, shot, version, layer): print '\t> %s > %s > %s > %s > core.renders.render_3d_passes' % (dept, shot, version, layer) #lets set up some vars self.jobdict = jobdict self.job = jobdict.keys()[0] self.dept = dept self.shot = shot self.version = version self.layer = layer if self.layer == 'loose': self.renderroot = os.path.join(core.jobsRoot, self.job, 'vfx', self.dept, self.shot, 'Render_Pictures', self.version) else: self.renderroot = os.path.join(core.jobsRoot, self.job, 'vfx', self.dept, self.shot, 'Render_Pictures', self.version, self.layer) # the getSequences class returns a list - not an object seq_class = pyseq.getSequences(self.renderroot) self.passes = [] for each in seq_class: self.passes.append(each.split(' ')[-1]) self.jobdict[self.job][self.dept]['shots'][shot]['renders'][self.version][self.layer] = self.passes
def OutputMOV(self): self.nodeWrites = nuke.selectedNodes('Write') self.nodeContactSheet = nuke.selectedNodes('ContactSheet') self.nodeReformat = nuke.selectedNodes('Reformat') self.allSelectNode = nuke.selectedNodes() #self.selectRead=nuke.selectedNodes('Read') if not self.nodeWrites: nuke.message( '\xe6\xb2\xa1\xe6\x9c\x89\xe9\x80\x89\xe6\x8b\xa9write\xe8\x8a\x82\xe7\x82\xb9' ) return if not self.nodeContactSheet: nuke.message( '\xe6\xb2\xa1\xe6\x9c\x89\xe9\x80\x89\xe6\x8b\xa9ContactSheet\xe8\x8a\x82\xe7\x82\xb9' ) return if not self.nodeReformat: nuke.message( '\xe6\xb2\xa1\xe6\x9c\x89\xe9\x80\x89\xe6\x8b\xa9Reformat\xe8\x8a\x82\xe7\x82\xb9' ) return writeFile = self.nodeWrites[0]['file'].value() #输出的文件夹 outPutDir = os.path.dirname(writeFile) all = pyseq.getSequences(outPutDir) if not all: nuke.message( "write\xe8\x8a\x82\xe7\x82\xb9\xe6\xb2\xa1\xe6\x9c\x89\xe8\xbe\x93\xe5\x87\xba\xe7\xb4\xa0\xe6\x9d\x90" ) return dirNames = all[0].path() print dirNames dirName = pyseq.getSequences(dirNames) print dirName if dirName and dirName[0].length() == 1: createReadNode = nuke.nodes.Read() ReadPath = dirNames.replace("\\", '/') createReadNode['file'].setValue(ReadPath) createReadNode['origfirst'].setValue(1) createReadNode['origlast'].setValue(1) createReadNode['first'].setValue(1) createReadNode['last'].setValue(1) createReadNode['on_error'].setValue('cheeckerboard') _w = self.nodeContactSheet[0]['width'].value( ) * self.nodeReformat[0]['scale'].value() _h = self.nodeContactSheet[0]['height'].value( ) * self.nodeReformat[0]['scale'].value() _width = int(_w) _height = int(_h) ReadOFormat = createReadNode['format'].value() Flag = True j = 0 if ReadOFormat.width() != _width or ReadOFormat.height( ) != _height: allFormat = nuke.formats() for eachFormat in allFormat: if eachFormat.width() == _width and eachFormat.height( ) == _height: myFormat = eachFormat.name() if myFormat != None: createReadNode['format'].setValue(myFormat) Flag = False break if Flag: #键的名字 mySize = "" while True: mySize = ('my_Size%s' % j) if mySize not in [ eachFormat.name() for eachFormat in allFormat ]: break else: j += 1 widthHeight = str(_width) + " " + str(_height) square = widthHeight + " " + mySize nuke.addFormat(square) createReadNode['format'].setValue(mySize) createNodeWrite = nuke.nodes.Write() mydirName = writeFile.split("/") myFiledirName = os.path.dirname(writeFile) getSequences = pyseq.getSequences(myFiledirName)[0] getStartFrame = getSequences[0]._get_filename().split(".")[1] getLastFrame = getSequences[-1]._get_filename().split(".")[1] myWritePath = '/'.join(mydirName[0:-2]) + "/" + mydirName[ -3] + "(" + getStartFrame + "-" + getLastFrame + ").mov" createNodeWrite['file'].setValue(myWritePath) createNodeWrite.setInput(0, createReadNode) createNodeWrite['file_type'].setValue('mov') createNodeWrite['meta_codec'].setValue('jpeg') createNodeWrite['mov64_quality_min'].setValue(10) createNodeWrite['mov64_quality_max'].setValue(10) self.nukeName = '/'.join( mydirName[0:-2]) + "/" + "mov_" + mydirName[ -3] + "_(" + getStartFrame + "-" + getLastFrame + ").nk" else: createReadNode = nuke.nodes.Read() createReadNode['file'].setValue(writeFile) createReadNode['on_error'].setValue('cheeckerboard') _w = self.nodeContactSheet[0]['width'].value( ) * self.nodeReformat[0]['scale'].value() _h = self.nodeContactSheet[0]['height'].value( ) * self.nodeReformat[0]['scale'].value() _width = int(_w) _height = int(_h) ReadOFormat = createReadNode['format'].value() Flag = True j = 0 if ReadOFormat.width() != _width or ReadOFormat.height( ) != _height: allFormat = nuke.formats() for eachFormat in allFormat: if eachFormat.width() == _width and eachFormat.height( ) == _height: myFormat = eachFormat.name() if myFormat != None: createReadNode['format'].setValue(myFormat) Flag = False break if Flag: #键的名字 mySize = "" while True: mySize = ('my_Size%s' % j) if mySize not in [ eachFormat.name() for eachFormat in allFormat ]: break else: j += 1 widthHeight = str(_width) + " " + str(_height) square = widthHeight + " " + mySize nuke.addFormat(square) createReadNode['format'].setValue(mySize) createNodeWrite = nuke.nodes.Write() mydirName = writeFile.split("/") myFiledirName = os.path.dirname(writeFile) getSequences = pyseq.getSequences(myFiledirName)[0] getStartFrame = getSequences[0]._get_filename().split(".")[1] getLastFrame = getSequences[-1]._get_filename().split(".")[1] print getStartFrame print getLastFrame createReadNode['origfirst'].setValue(int(getStartFrame)) createReadNode['origlast'].setValue(int(getLastFrame)) createReadNode['first'].setValue(int(getStartFrame)) createReadNode['last'].setValue(int(getLastFrame)) myWritePath = '/'.join(mydirName[0:-2]) + "/" + mydirName[ -3] + "(" + getStartFrame + "-" + getLastFrame + ").mov" createNodeWrite['file'].setValue(myWritePath) createNodeWrite.setInput(0, createReadNode) createNodeWrite['file_type'].setValue('mov') createNodeWrite['meta_codec'].setValue('jpeg') createNodeWrite['mov64_quality_min'].setValue(10) createNodeWrite['mov64_quality_max'].setValue(10) self.nukeName = '/'.join( mydirName[0:-2]) + "/" + "mov_" + mydirName[ -3] + "_(" + getStartFrame + "-" + getLastFrame + ").nk" print self.nukeName for nodes in self.allSelectNode: nuke.delete(nodes) nuke.scriptSaveAs(self.nukeName)
def myCheckFrames(self): self.delMyBackdrops() self.myReadsNameDict.clear() self.myReadsStartDict.clear() self.myReadsLastDict.clear() j = 1 addBackdropFlag = False noFileList = {} if self.myReads: for read in self.myReads: readFilePath = read['file'].value() if readFilePath: fileType = os.path.splitext(readFilePath)[-1] readFileStart = read['first'].value() readFileLast = read['last'].value() self.myReadsNameDict.update({read: readFilePath}) self.myReadsStartDict.update({read: readFileStart}) self.myReadsLastDict.update({read: readFileLast}) #查询位数 #numPlaces = len('%d' % readFileLast) numPlaces = int( readFilePath.split("/")[-1].split(".")[1].split("%0") [-1].split('d')[0]) if fileType != '.mov' and readFileStart != readFileLast: k = [] pathSplit = readFilePath.split('/') joinPath = '/'.join(pathSplit[0:-1]) sequences = pyseq.getSequences(joinPath) #k=sequences[0].missing() for i in range(readFileStart, readFileLast + self.selectFrame, self.selectFrame): checkPath = readFilePath.replace( ('.%' + '0%dd' % numPlaces), (('.%' + '0%dd' % numPlaces) % i)) print checkPath if not os.path.isfile(checkPath): print "aaa\n" k.append(i) if k: sortNum = self.mySortNum(k) numTT = '' lenNum = len(sortNum) for nn in sortNum: if str(type(nn)).find('int') >= 0: numTT += '%s,' % nn else: numTT += '%s-%s,' % (nn[0], nn[1]) tmpText = readFilePath + '\n' + numTT[:-1] if not tmpText in noFileList.values(): noFileList.update({read.name(): tmpText}) addBackdropFlag = True else: if not os.path.isfile(readFilePath): if not readFilePath in noFileList.values(): noFileList.update({read.name(): readFilePath}) addBackdropFlag = True if addBackdropFlag: self.setSelecteNone() read.setSelected(True) myBackdrop = nukescripts.autoBackdrop() myBackdrop.knob('tile_color').setValue(4278190335L) myBackdrop.knob('name').setValue('Lack Frames %s' % j) myBackdrop.knob('label').setValue( '\xe7\xbc\xba\xe5\xb8\xa7') addBackdropFlag = False j = j + 1 self.setSelecteNone() return noFileList
def myOrigFrame(self): j = 1 self.myReads = nuke.selectedNodes('Read') if len(self.myReads) == 0: self.myReads = nuke.allNodes('Read') #打X的素材不在范围内 if self.myReads: tmpList = [] for eachRead in self.myReads: if not eachRead['disable'].value(): tmpList.append(eachRead) self.myReads = tmpList if len(self.myReads) == 0: nuke.message('No Reads!') return self.myFormatCheck_UI() if self.formatFlag: try: if nuke.root().firstFrame() == nuke.frame(): nuke.activeViewer().frameControl(+1) elif nuke.root().lastFrame() == nuke.frame(): nuke.activeViewer().frameControl(-1) else: nuke.activeViewer().frameControl(+1) except: nuke.message( '\xe8\xaf\xb7\xe5\x88\x9b\xe5\xbb\xba\xe4\xb8\x80\xe4\xb8\xaaviewer\xe8\xa7\x86\xe7\xaa\x97\xef\xbc\x81' ) return if self.myReads: for read in self.myReads: Flag = True readFilePath = read['file'].value() if readFilePath: if self.formatFlag: formatW = read.width() formatH = read.height() ReadOFormat = read['format'].value() if ReadOFormat.width( ) != formatW or ReadOFormat.height() != formatH: if self.myOrangeDict: for orange in self.myOrangeDict.keys(): sizeW = self.myOrangeDict[orange].split( " ")[0] sizeH = self.myOrangeDict[orange].split( " ")[1] if sizeW == formatW and sizeH == formatH: read['format'].setValue(orange) Flag = False break if Flag: allFormat = nuke.formats() for eachFormat in allFormat: if eachFormat.width( ) == formatW and eachFormat.height( ) == formatH: myFormat = eachFormat.name() if myFormat != None: read['format'].setValue(myFormat) Flag = False break if Flag: while True: mySize = ('my_Size%s' % j) if mySize not in [ eachFormat.name() for eachFormat in allFormat ]: break else: j += 1 widthHeight = str(formatW) + " " + str( formatH) self.myOrangeDict.update( {mySize: widthHeight}) square = widthHeight + " " + mySize nuke.addFormat(square) read['format'].setValue(mySize) if self.checkFlag: readDir = os.path.split(readFilePath)[0] frameOrange = pyseq.getSequences(readDir) for frames in frameOrange: myPath = frames.path() if os.path.isdir(myPath): continue else: if frames.tail(): firstFrameName = frames[0]._get_filename() lastFrameName = frames[-1]._get_filename() readFileStart = firstFrameName.split( ".")[-2] readFileLast = lastFrameName.split(".")[-2] read['origfirst'].setValue( int(readFileStart)) read['origlast'].setValue( int(readFileLast)) read['first'].setValue(int(readFileStart)) read['last'].setValue(int(readFileLast)) else: if self.formatFlag or self.checkFlag: nuke.message('OK')
return cmd if __name__ == '__main__': renderPath = '/show/CM/management/scan/20140314_CG_SOURCE/Blood' thefolderList = [ x for x in glob.glob( renderPath + '/*' ) ] thefolderList.sort() temp = [] for root , dirs , files in os.walk( renderPath ): for d in dirs: thepath = os.path.join( root , d ) if os.path.isdir( thepath ): if len( [x for x in glob.glob( thepath + '/*' ) if os.path.isdir(x) ] ) == 0: temp.append( thepath ) for x in temp: for s in pyseq.getSequences(x): print x+ '/'+ s.format('%h%p%t') opt = {} opt['showname'] = 'CM' opt['dpxSeq'] = x+ '/'+ s.format('%h%p%t') opt['start'] = s.start() opt['end'] = s.end() cmd = renderMOVcmdOnNuke( opt ) print cmd # devSeqPath = r'/core/tmp/show/KD/management/scan/20131216/R2MG' # rand = RenderIO() # imageSeqList = rand.getImageSeqList( devSeqPath ) # seqName , num , ext = rand.getSeqName( imageSeqList ) # jpgSeqName = rand.getJPGseqName( seqName ) # movname = rand.getMOVname( seqName )
def importImage(self, oldPath, options, i): j = i myOldPath = oldPath all = pyseq.getSequences(myOldPath) #第几个文件夹中导出Read节点 if options != 0: for dirName in all: myOldPath = dirName.path() if os.path.isdir(myOldPath) and (options - 1) > self.list: self.list = int(self.list + 1) self.importImage(myOldPath, options, j) elif (not os.path.isdir(myOldPath)) and (options - 1) == self.list: Flag = True Flags = True myDir = myOldPath.split("\\") myDirs = '/'.join(myDir[0:-1]) if dirName.length() == 1: the_head = dirName.head() if the_head == "Thumbs.db": continue #单帧 else: if the_head.find('.exr') >= 0 or the_head.find( '.jpg') >= 0 or the_head.find( '.tif') >= 0 or the_head.find( '.iff') >= 0 or the_head.find( '.tga') >= 0 or the_head.find( '.png') >= 0: if self.number > 0 and self.number % 60 == 0: if not os.path.isdir("D:/nukeFile"): os.makedirs("D:/nukeFile") nuke.scriptSave("D:/nukeFile/v%d.nk" % 1) nuke.selectAll() nukescripts.node_delete( popupOnError=True) else: fileName = int(self.number / 60) nuke.scriptSave("D:/nukeFile/v%d.nk" % fileName) nuke.selectAll() nukescripts.node_delete( popupOnError=True) self.number = self.number + 1 firstFrameName = dirName[0]._get_filename() #创建节点 nodeRead = nuke.nodes.Read() nodeRead['postage_stamp'].setValue(False) #素材路径 setData = os.path.join(myDirs, firstFrameName) nodeRead['file'].setValue( '%s' % setData.replace('\\', '/')) nodeRead['origfirst'].setValue(1) nodeRead['origlast'].setValue(1) nodeRead['first'].setValue(1) nodeRead['last'].setValue(1) nodeRead['on_error'].setValue('checkerboard') formatW = nodeRead.width() formatH = nodeRead.height() ReadOFormat = nodeRead['format'].value() if ReadOFormat.width( ) != formatW or ReadOFormat.height( ) != formatH: allFormat = nuke.formats() if self.myOrangeDict: for myOrange in self.myOrangeDict.keys( ): SazeW = self.myOrangeDict[ myOrange].split(" ")[0] SazeH = self.myOrangeDict[ myOrange].split(" ")[1] if SazeW == formatW and SazeH == formatH: nodeRead['format'].setValue( myOrange) Flag = False break if Flag: for eachFormat in allFormat: if eachFormat.width( ) == formatW and eachFormat.height( ) == formatH: myFormat = eachFormat.name() if myFormat != None: nodeRead[ 'format'].setValue( myFormat) Flag = False break if Flag: while True: mySize = ('my_Size%s' % j) if mySize not in [ eachFormat.name() for eachFormat in allFormat ]: break else: j += 1 widthHeight = str( formatW) + " " + str(formatH) self.myOrangeDict.update( {mySize: widthHeight}) square = widthHeight + " " + mySize nuke.addFormat(square) nodeRead['format'].setValue(mySize) nodeReformat = nuke.nodes.Reformat( ) nodeWrite = nuke.nodes.Write() nodeReformat.setInput(0, nodeRead) nodeWrite.setInput(0, nodeReformat) if the_tail == '.exr': nodeWrite['file_type'].setValue("exr") nodeWrite['datatype'].setValue(0) nodeWrite['channels'].setValue("all") nodeWrite['compression'].setValue(2) else: filetype = the_tail.split(".")[1] nodeWrite['channels'].setValue("all") if filetype == "iff": filetype = "tiff" nodeWrite['file_type'].setValue( filetype) nodeWrite['compression'].setValue(2) else: nodeWrite['file_type'].setValue( filetype) oldFilePath = '/'.join( self.oldPaths.split("/")[0:-1]) WriteFile = setData.replace( oldFilePath, self.newPaths) if the_tail == ".iff": WriteFile.replace("iff", "tiff") nodeWrite['file'].setValue(WriteFile) myNewPath = os.path.dirname(WriteFile) if not os.path.isdir(myNewPath): os.makedirs(myNewPath) ReformatFormat = nodeReformat['format'].value() if ReformatFormat.width( ) != 500 or ReformatFormat.height() != 500: allFormat = nuke.formats() for eachFormat in allFormat: if eachFormat.width( ) == 500 and eachFormat.height( ) == 500: myFormat = eachFormat.name() if myFormat != None: nodeReformat[ 'format'].setValue( myFormat) Flag = False break if Flag: while True: mySize = ('my_Size%s' % j) if mySize not in [ eachFormat.name() for eachFormat in allFormat ]: break else: j += 1 widthHeight = str(formatW) + " " + str( formatH) square = widthHeight + " " + mySize nuke.addFormat(square) nodeReformat['format'].setValue(mySize) if self.number > 0: if not os.path.isdir("D:/nukeFile"): os.makedirs("D:/nukeFile") nuke.scriptSave("D:/nukeFile/v%d.nk" % 1) fileName = int(self.number / 60) + 1 nuke.scriptSave("D:/nukeFile/v%d.nk" % fileName) #序列帧 else: the_tail = dirName.tail() if the_tail: if the_tail == '.exr' or the_tail == '.jpg' or the_tail == '.tif' or the_tail == '.iff' or the_tail == '.tiff' or the_tail == '.tga' or the_tail == '.png': if self.number > 0 and self.number % 60 == 0: if not os.path.isdir("D:/nukeFile"): os.makedirs("D:/nukeFile") nuke.scriptSave("D:/nukeFile/v%d.nk" % 1) nuke.selectAll() nukescripts.node_delete( popupOnError=True) else: fileName = int(self.number / 60) nuke.scriptSave("D:/nukeFile/v%d.nk" % fileName) nuke.selectAll() nukescripts.node_delete( popupOnError=True) self.number = self.number + 1 firstFrameName = dirName[0]._get_filename() lastFrameName = dirName[-1]._get_filename() #the_firstframes=int(firstFrameName.split(".")[-2]) #the_lastframes = int(lastFrameName.split(".")[-2]) if len(firstFrameName.split(".")) == 2: the_firstframes = int( firstFrameName.split(".")[-2].replace( myDir[-2], "")) the_lastframes = int( lastFrameName.split(".")[-2].replace( myDir[-2], "")) else: #获取第一帧的文件名 the_firstframes = int( firstFrameName.split(".")[-2]) the_lastframes = int( lastFrameName.split(".")[-2]) nodeRead = nuke.nodes.Read() nodeRead['postage_stamp'].setValue(False) setData = os.path.join(myDirs, firstFrameName) nodeRead['file'].setValue( '%s' % setData.replace('\\', '/')) formatW = nodeRead.width() formatH = nodeRead.height() widthHeight = str(formatW) + " " + str(formatH) ReadOFormat = nodeRead['format'].value() if ReadOFormat.width( ) != formatW or ReadOFormat.height( ) != formatH: if self.myOrangeDict: for myOrange in self.myOrangeDict.keys( ): SazeW = self.myOrangeDict[ myOrange].split(" ")[0] SazeH = self.myOrangeDict[ myOrange].split(" ")[1] if SazeW == formatW and SazeH == formatH: nodeRead['format'].setValue( myOrange) Flag = False break if Flag: allFormat = nuke.formats() for eachFormat in allFormat: if eachFormat.width( ) == formatW and eachFormat.height( ) == formatH: myFormat = eachFormat.name() if myFormat != None: nodeRead[ 'format'].setValue( myFormat) Flag = False break if Flag: while True: mySize = ('my_Size%s' % j) if mySize not in [ eachFormat.name() for eachFormat in allFormat ]: break else: j += 1 widthHeight = str( formatW) + " " + str(formatH) self.myOrangeDict.update( {mySize: widthHeight}) square = widthHeight + " " + mySize nuke.addFormat(square) nodeRead['format'].setValue(mySize) #查找位数 if len(firstFrameName.split(".")) == 2: num = firstFrameName.split( ".")[-2].replace(myDir[-2], "") numPlaces = len("%s" % num) the_image = dirName.tail() #number=lastFrameName.split(".") #name=".".join(number[0:-2]) setData = myDirs + "/" + myDir[ -2] + "%" + "0%dd" % numPlaces + the_image else: num = firstFrameName.split(".")[-2] numPlaces = len("%s" % num) the_image = dirName.tail() number = lastFrameName.split(".") name = ".".join(number[0:-2]) setData = myDirs + "/" + name + ".%" + "0%dd" % numPlaces + the_image nodeRead['file'].setValue(setData) nodeRead['origfirst'].setValue(the_firstframes) nodeRead['origlast'].setValue(the_lastframes) nodeRead['first'].setValue(the_firstframes) nodeRead['last'].setValue(the_lastframes) nodeRead['on_error'].setValue('checkerboard') nodeReformat = nuke.nodes.Reformat() nodeWrite = nuke.nodes.Write() nodeReformat.setInput(0, nodeRead) nodeWrite.setInput(0, nodeReformat) if the_tail == '.exr': nodeWrite['file_type'].setValue("exr") nodeWrite['channels'].setValue("all") nodeWrite['compression'].setValue(2) nodeWrite['datatype'].setValue(0) else: filetype = the_tail.split(".")[1] nodeWrite['channels'].setValue("all") if filetype == "iff": filetype = "tiff" nodeWrite['file_type'].setValue( filetype) nodeWrite['compression'].setValue(2) else: nodeWrite['file_type'].setValue( filetype) oldFilePath = '/'.join( self.oldPaths.split("/")[0:-1]) WriteFile = setData.replace( oldFilePath, self.newPaths) if the_tail == ".iff": WriteFile.replace(".iff", "tiff") nodeWrite['file'].setValue(WriteFile) myNewPath = os.path.dirname(WriteFile) if not os.path.isdir(myNewPath): os.makedirs(myNewPath) ReformatFormat = nodeReformat['format'].value() if ReformatFormat.width( ) != 500 or ReformatFormat.height() != 500: allFormat = nuke.formats() for eachFormat in allFormat: if eachFormat.width( ) == 500 and eachFormat.height( ) == 500: myFormat = eachFormat.name() if myFormat != None: nodeReformat[ 'format'].setValue( myFormat) Flag = False break if Flag: while True: mySize = ('my_Size%s' % j) if mySize not in [ eachFormat.name() for eachFormat in allFormat ]: break else: j += 1 widthHeight = str(formatW) + " " + str( formatH) square = widthHeight + " " + mySize nuke.addFormat(square) nodeReformat['format'].setValue(mySize) if self.number > 0: if not os.path.isdir("D:/nukeFile"): os.makedirs("D:/nukeFile") nuke.scriptSave("D:/nukeFile/v%d.nk" % 1) fileName = int(self.number / 60) + 1 nuke.scriptSave("D:/nukeFile/v%d.nk" % fileName) else: myDirs = '/'.join(myDir[0:-1]) mySequenceDir = myDir[-1].split('-') print mySequenceDir num_1 = mySequenceDir[0].split("_") num_2 = mySequenceDir[1].split("_") for i in range(int(num_2[0])): g = str(i + 1) myOldPath = myDirs + "/" + num_1[ 0] + "_" + g + "_" + num_2[-1] if i != 0: self.list = self.list + 1 self.importImage(myOldPath, options, j) else: #print myOldPath self.list = 1 #导入所有 elif options == 0: for dirName in all: myOldPath = dirName.path() if os.path.isdir(myOldPath): self.importImage(myOldPath, options, j) else: Flag = True Flags = True myDir = myOldPath.split('\\') myDirs = "/".join(myDir[0:-1]) if dirName.length() == 1: the_head = dirName.head() if the_head == "Thumbs.db": continue #单帧 else: if the_head.find('.exr') >= 0 or the_head.find( '.jpg') >= 0 or the_head.find( '.tif') >= 0 or the_head.find( '.iff') >= 0 or the_head.find( '.tga') >= 0 or the_head.find( '.png') >= 0: if self.number > 0 and self.number % 60 == 0: if not os.path.isdir("D:/nukeFile"): os.makedirs("D:/nukeFile") nuke.scriptSave("D:/nukeFile/v%d.nk" % 1) nuke.selectAll() nukescripts.node_delete( popupOnError=True) else: fileName = int(self.number / 60) nuke.scriptSave("D:/nukeFile/v%d.nk" % fileName) nuke.selectAll() nukescripts.node_delete( popupOnError=True) self.number = self.number + 1 firstFrameName = dirName[0]._get_filename() #创建Read节点 nodeRead = nuke.nodes.Read() nodeRead['postage_stamp'].setValue(False) #素材路径 setData = os.path.join(myDirs, firstFrameName) nodeRead['file'].setValue( '%s' % setData.replace("\\", "/")) nodeRead['origfirst'].setValue(1) nodeRead['origlast'].setValue(1) nodeRead['first'].setValue(1) nodeRead['last'].setValue(1) nodeRead["on_error"].setValue('checkerboard') formatW = nodeRead.width() formatH = nodeRead.height() ReadOFormat = nodeRead['format'].value() if ReadOFormat.width( ) != formatW or ReadOFormat.height( ) != formatH: allFormat = nuke.format() if self.myOrangeDict: for myOrange in self.myOrangeDict.keys( ): SazeW = self.myOrangeDict[ 'myOrange'].split(" ")[0] SazeH = self.myOrangeDict[ 'myOrange'].split(" ")[1] if SazeW == formatW or SazeH == formatH: nodeRead['format'].setValue( myOrange) Flag = False break if Flag: for eachFormat in allFormat: if eachFormat.width == formatW and eachFormat.height == formatH: myFormat = eachFormat.name() if myFormat != None: nodeRead[ 'format'].setValue( myFormat) Flag = False break if Flag: #键的名字 while True: mySize = ('my_Size%s' % j) if mySize not in [ eachFormat.name() for eachFormat in allFormat ]: break else: j += 1 widthHeight = str( formatW) + " " + str(formatH) self.myOrangeDict.update( {mySize: widthHeight}) square = widthHeight + " " + mySize nuke.addFormat(square) nodeRead['format'].setValue(mySize) nodeReformat = nuke.nodes.Reformat() nodeReformat.setInput(0, nodeRead) nodeWrite = nuke.nodes.Write() nodeWrite.setInput(0, nodeReformat) if the_tail == '.exr': nodeWrite['file_type'].setValue("exr") nodeWrite['channels'].setValue("all") nodeWrite['compression'].setValue(2) nodeWrite['datatype'].setValue(0) else: filetype = the_tail.split(".")[1] nodeWrite['channels'].setValue("all") if filetype == "iff": filetype = "tiff" nodeWrite['file_type'].setValue( filetype) nodeWrite['compression'].setValue(2) else: nodeWrite['file_type'].setValue( filetype) oldFilePath = '/'.join( self.oldPaths.split("/")[0:-1]) WriteFile = setData.replace( oldFilePath, self.newPaths) if the_tail == '.iff': WriteFile = WriteFile.replace( ".iff", ".tiff") nodeWrite['file'].setValue(WriteFile) myNewPath = os.path.dirname(WriteFile) if not os.path.isdir(myNewPath): os.makedirs(myNewPath) ReformatFormat = nodeReformat['format'].value() if ReformatFormat.width( ) != 500 or ReformatFormat.height() != 500: allFormat = nuke.formats() for eachFormat in allFormat: if eachFormat.width( ) == 500 and eachFormat.height( ) == 500: myFormat = eachFormat.name() if myFormat != None: nodeReformat[ 'format'].setValue( myFormat) Flags = False break if Flags: while True: mySize = ('my_Size%s' % j) if mySize not in [ eachFormat.name() for eachFormat in allFormat ]: break else: j += 1 widthHeight = str(formatW) + " " + str( formatH) square = widthHeight + " " + mySize nuke.addFormat(square) nodeReformat['format'].setValue(mySize) if self.number > 0: if not os.path.isdir("D:/nukeFile"): os.makedirs("D:/nukeFile") nuke.scriptSave("D:/nukeFile/v%d.nk" % 1) fileName = int(self.number / 60) + 1 nuke.scriptSave("D:/nukeFile/v%d.nk" % fileName) #序列帧 else: the_tail = dirName.tail() if the_tail: if the_tail == '.exr' or the_tail == '.jpg' or the_tail == '.tif' or the_tail == '.iff' or the_tail == '.tiff' or the_tail == '.tga' or the_tail == '.png': if self.number > 0 and self.number % 60 == 0: if not os.path.isdir("D:/nukeFile"): os.makedirs("D:/nukeFile") nuke.scriptSave("D:/nukeFile/v%d.nk" % 1) nuke.selectAll() nukescripts.node_delete( popupOnError=True) else: fileName = int(self.number / 60) nuke.scriptSave("D:/nukeFile/v%d.nk" % fileName) nuke.selectAll() nukescripts.node_delete( popupOnError=True) self.number = self.number + 1 firstFrameName = dirName[0]._get_filename() lastFrameName = dirName[-1]._get_filename() if len(firstFrameName.split(".")) == 2: the_firstframes = int( firstFrameName.split(".")[-2].replace( myDir[-2], "")) the_lastframes = int( lastFrameName.split(".")[-2].replace( myDir[-2], "")) else: #获取第一帧的文件名 the_firstframes = int( firstFrameName.split(".")[-2]) the_lastframes = int( lastFrameName.split(".")[-2]) nodeRead = nuke.nodes.Read() nodeRead['postage_stamp'].setValue(False) setData = os.path.join(myDirs, firstFrameName) nodeRead['file'].setValue( "%s" % setData.replace("\\", '/')) #节点的大小 formatW = nodeRead.width() formatH = nodeRead.height() widthHeight = str(formatW) + " " + str(formatH) ReadOFormat = nodeRead['format'].value() if ReadOFormat.width( ) != formatW or ReadOFormat.height( ) != formatH: if self.myOrangeDict: for myOrange in self.myOrangeDict.keys( ): SazeW = self.myOrangeDict[ myOrange].split(" ")[0] SazeH = self.myOrangeDict[ myOrange].split(" ")[1] if SazeW == formatW and SazeH == formatH: nodeRead['format'].setValue( myOrange) Flag = False break if Flag: allFormat = nuke.formats() for eachFormat in allFormat: if eachFormat.width( ) == formatW and eachFormat.height( ) == formatH: myFormat = eachFormat.name() if myFormat != None: nodeRead[ 'format'].setValue( myFormat) Flag = False break if Flag: while True: mySize = ('my_Size%s' % j) if mySize not in [ eachFormat.name() for eachFormat in allFormat ]: break else: j += 1 widthHeight = str( formatW) + " " + str(formatH) self.myOrangeDict.update( {mySize: widthHeight}) square = widthHeight + " " + mySize nuke.addFormat(square) nodeRead['format'].setValue(mySize) #查找位数 if len(firstFrameName.split(".")) == 2: num = firstFrameName.split( ".")[-2].replace(myDir[-2], "") numPlaces = len("%s" % num) the_image = dirName.tail() #number=lastFrameName.split(".") #name=".".join(number[0:-2]) setData = myDirs + "/" + myDir[ -2] + "%" + "0%dd" % numPlaces + the_image else: num = firstFrameName.split(".")[-2] numPlaces = len("%s" % num) the_image = dirName.tail() number = lastFrameName.split(".") name = ".".join(number[0:-2]) setData = myDirs + "/" + name + ".%" + "0%dd" % numPlaces + the_image nodeRead['file'].setValue(setData) nodeRead['origfirst'].setValue(the_firstframes) nodeRead['origlast'].setValue(the_lastframes) nodeRead['first'].setValue(the_firstframes) nodeRead['last'].setValue(the_lastframes) nodeRead['on_error'].setValue('checkerboard') nodeReformat = nuke.nodes.Reformat() nodeWrite = nuke.nodes.Write() nodeReformat.setInput(0, nodeRead) nodeWrite.setInput(0, nodeReformat) if the_tail == '.exr': nodeWrite['file_type'].setValue("exr") nodeWrite['datatype'].setValue(0) nodeWrite['channels'].setValue("all") nodeWrite['compression'].setValue(2) else: filetype = the_tail.split(".")[1] nodeWrite['channels'].setValue("all") if filetype == "iff": filetype = "tiff" nodeWrite['file_type'].setValue( filetype) nodeWrite['compression'].setValue(2) else: nodeWrite['file_type'].setValue( filetype) oldFilePath = '/'.join( self.oldPaths.split("/")[0:-1]) WriteFile = setData.replace( oldFilePath, self.newPaths) if the_tail == '.iff': WriteFile = WriteFile.replace( ".iff", ".tiff") nodeWrite['file'].setValue(WriteFile) myNewPath = os.path.dirname(WriteFile) if not os.path.isdir(myNewPath): os.makedirs(myNewPath) ReformatFormat = nodeReformat['format'].value() if ReformatFormat.width( ) != 500 or ReformatFormat.height() != 500: allFormat = nuke.formats() for eachFormat in allFormat: if eachFormat.width( ) == 500 and eachFormat.height( ) == 500: myFormat = eachFormat.name() if myFormat != None: nodeReformat[ 'format'].setValue( myFormat) Flags = False break if Flags: while True: mySize = ('my_Size%s' % j) if mySize not in [ eachFormat.name() for eachFormat in allFormat ]: break else: j += 1 widthHeight = str(500) + " " + str(500) square = widthHeight + " " + mySize nuke.addFormat(square) nodeReformat['format'].setValue(mySize) if self.number > 0: if not os.path.isdir("D:/nukeFile"): os.makedirs("D:/nukeFile") nuke.scriptSave("D:/nukeFile/v%d.nk" % 1) fileName = int(self.number / 60) + 1 nuke.scriptSave("D:/nukeFile/v%d.nk" % fileName) else: myDirs = '/'.join(myDir[0:-1]) mySequenceDir = myDir[-1].split('-') num_1 = mySequenceDir[0].split("_") num_2 = mySequenceDir[1].split("_") for i in range(int(num_2[0])): g = str(i + 1) myOldPath = myDirs + "/" + num_1[ 0] + "_" + g + "_" + num_2[-1] self.importImage(myOldPath, options, j) else: for dirtList in dirName: myOldPath = dirtList.path if os.path.isdir(myOldPath): self.importImage(myOldPath, options, j)
def Bulk_Samples_Conversion(self,oldfilepath,newfilepath): #print oldfilepath #print newfilepath j=1 #print self.myContactReadDict for mykey in self.myContactReadDict.keys(): for myRead in self.myContactReadDict[mykey]: self.myReads.remove(myRead) readPath=myRead['file'].value() filePath = readPath.replace(oldfilepath, newfilepath) #print filePath readDir=os.path.split(filePath)[0] if not os.path.isdir(readDir): self.warning.append(myRead.name()) continue Flag=True myRead['file'].setValue(filePath) formatW=myRead.width() formatH = myRead.height() #print formatH ReadOFormat = myRead['format'].value() #print ReadOFormat.width() if ReadOFormat.width() != formatW or ReadOFormat.height() != formatH: allFormat = nuke.formats() if self.myOrangeDict: for myOrange in self.myOrangeDict.keys(): SazeW = self.myOrangeDict[myOrange].split(" ")[0] SazeH = self.myOrangeDict[myOrange].split(" ")[1] if SazeW == formatW and SazeH == formatH: myRead['format'].setValue(myOrange) Flag = False break if Flag: for eachFormat in allFormat: if eachFormat.width() == formatW and eachFormat.height() == formatH: #print eachFormat.width() #print formatW myFormat = eachFormat.name() print myFormat if myFormat != None: #print "sssss" myRead['format'].setValue(myFormat) Flag = False break if Flag: #键的名字 while True: mySize = ('my_Size%s' % j) #print mySize if mySize not in [eachFormat.name() for eachFormat in allFormat]: break else: j += 1 #print j widthHeight = str(formatW) + " " + str(formatH) self.myOrangeDict.update({mySize:widthHeight}) square = widthHeight+" "+mySize nuke.addFormat(square) myRead['format'].setValue(mySize) frameOrange=pyseq.getSequences(readDir) for frames in frameOrange: myPath = frames.path() if os.path.isdir(myPath): continue else: if frames.tail(): if frames.length()==1: myRead['origfirst'].setValue(1) myRead['origlast'].setValue(1) myRead['first'].setValue(1) myRead['last'].setValue(1) else: firstFrameName = frames[0]._get_filename() lastFrameName = frames[-1]._get_filename() readFileStart=firstFrameName.split(".")[-2] readFileLast=lastFrameName.split(".")[-2] myRead['origfirst'].setValue(int(readFileStart)) myRead['origlast'].setValue(int(readFileLast)) myRead['first'].setValue(int(readFileStart)) myRead['last'].setValue(int(readFileLast)) _w=self.myContactReadDict[mykey][0].knob('format').value().width() _h=self.myContactReadDict[mykey][0].knob('format').value().height() #print _w #print _h constRows=mykey['rows'].value() constColumns=mykey['columns'].value() #print constRows #print constColumns mykey['height'].setValue(constRows*_h) mykey['width'].setValue(constColumns*_w) if self.myReads: for myRead in self.myReads: readPath=myRead['file'].value() filePath = readPath.replace(oldfilepath, newfilepath) Flag=True readDir=os.path.split(filePath)[0] if not os.path.isdir(readDir): self.warning.append(myRead.name()) continue myRead['file'].setValue(filePath) formatW=myRead.width() formatH = myRead.height() #print formatH ReadOFormat = myRead['format'].value() if ReadOFormat.width() != formatW or ReadOFormat.height() != formatH: allFormat = nuke.formats() if self.myOrangeDict: for myOrange in self.myOrangeDict.keys(): SazeW = self.myOrangeDict[myOrange].split(" ")[0] SazeH = self.myOrangeDict[myOrange].split(" ")[1] if SazeW == formatW and SazeH == formatH: myRead['format'].setValue(myOrange) Flag = False break if Flag: for eachFormat in allFormat: if eachFormat.width() == formatW and eachFormat.height() == formatH: myFormat = eachFormat.name() if myFormat != None: myRead['format'].setValue(myFormat) Flag = False break if Flag: #键的名字 while True: mySize = ('my_Size%s' % j) if mySize not in [eachFormat.name() for eachFormat in allFormat]: break else: j += 1 widthHeight = str(formatW) + " " + str(formatH) self.myOrangeDict.update({mySize:widthHeight}) square = widthHeight+" "+mySize nuke.addFormat(square) myRead['format'].setValue(mySize) frameOrange=pyseq.getSequences(readDir) for frames in frameOrange: myPath = frames.path() if os.path.isdir(myPath): continue else: if frames.tail(): if frames.length()==1: myRead['origfirst'].setValue(1) myRead['origlast'].setValue(1) myRead['first'].setValue(1) myRead['last'].setValue(1) else: firstFrameName = frames[0]._get_filename() lastFrameName = frames[-1]._get_filename() readFileStart=firstFrameName.split(".")[-2] readFileLast=lastFrameName.split(".")[-2] myRead['origfirst'].setValue(int(readFileStart)) myRead['origlast'].setValue(int(readFileLast)) myRead['first'].setValue(int(readFileStart)) myRead['last'].setValue(int(readFileLast)) if self.warning: nuke.message(str(self.warning)+"\xe8\x8a\x82\xe7\x82\xb9\xe6\x96\xb0\xe8\xb7\xaf\xe5\x8a\xb2\xe4\xb8\x8d\xe5\xad\x98\xe5\x9c\xa8")
def myFindFrame(self, path, i): # self.myReads = [] j = i myPath = path #print myPath all = pyseq.getSequences(myPath) #print all for dirName in all: #print dirName myPath = dirName.path() #print myPath if os.path.isdir(myPath): #print myPath self.myFindFrame(myPath, j) else: Flag = True myDir = myPath.split('\\') myDirs = '/'.join(myDir[0:-1]) #print myDirs imagesType = myDir[-2] if dirName.length() == 1: the_head = dirName.head() if the_head == 'Thumbs.db': continue #单帧 else: if the_head.find('.exr') >= 0 or the_head.find('.jpg') >= 0 or the_head.find('.tif') >= 0 or the_head.find('.iff') >= 0 or the_head.find('.tga') >= 0 or the_head.find('.png') >= 0: firstFrameName = dirName[0]._get_filename() #创建Read节点 nodeRead = nuke.nodes.Read() #素材路径 setData = os.path.join(myDirs, firstFrameName) nodeRead['file'].setValue('%s' % setData.replace('\\', '/')) nodeRead['origfirst'].setValue(1) nodeRead['origlast'].setValue(1) nodeRead['first'].setValue(1) nodeRead['last'].setValue(1) nodeRead['on_error'].setValue('cheeckerboard') formatW = nodeRead.width() formatH = nodeRead.height() ReadOFormat = nodeRead['format'].value() if ReadOFormat.width() != formatW or ReadOFormat.height() != formatH: allFormat = nuke.formats() if self.myOrangeDict: for myOrange in self.myOrangeDict.keys(): SazeW = self.myOrangeDict[myOrange].split(" ")[0] SazeH = self.myOrangeDict[myOrange].split(" ")[1] if SazeW == formatW and SazeH == formatH: nodeRead['format'].setValue(myOrange) Flag = False break if Flag: for eachFormat in allFormat: if eachFormat.width() == formatW and eachFormat.height() == formatH: myFormat = eachFormat.name() if myFormat != None: nodeRead['format'].setValue(myFormat) Flag = False break if Flag: #键的名字 while True: mySize = ('my_Size%s' % j) if mySize not in [eachFormat.name() for eachFormat in allFormat]: break else: j += 1 widthHeight = str(formatW) + " " + str(formatH) self.myOrangeDict.update({mySize:widthHeight}) square = widthHeight+" "+mySize nuke.addFormat(square) nodeRead['format'].setValue(mySize) self.myOneReads.append(nodeRead) self.mySeqClassDict.update({nodeRead: False}) if not imagesType in self.myImagesTClassDict.keys(): self.myImagesTClassDict.update({imagesType: [nodeRead]}) else: self.myImagesTClassDict[imagesType].append(nodeRead) #添加到类型字典中 # self.myClassDict.update({nodeRead:[myDir[-2], False]}) #序列帧 else: the_tail = dirName.tail() if the_tail: if the_tail == '.exr' or the_tail == '.jpg' or the_tail == '.tif' or the_tail == '.iff' or the_tail == '.tiff' or the_tail == '.tga' or the_tail == '.png': firstFrameName = dirName[0]._get_filename() lastFrameName = dirName[-1]._get_filename() #获取第一帧的文件名 the_firstframes = int(firstFrameName.split(".")[-2]) the_lastframes = int(lastFrameName.split(".")[-2]) nodeRead = nuke.nodes.Read() setData = os.path.join(myDirs, firstFrameName) nodeRead['file'].setValue('%s' % setData.replace('\\', '/')) formatW = nodeRead.width() formatH = nodeRead.height() widthHeight = str(formatW)+" "+str(formatH) ReadOFormat = nodeRead['format'].value() if ReadOFormat.width() != formatW or ReadOFormat.height() != formatH: if self.myOrangeDict: for myOrange in self.myOrangeDict.keys(): SazeW = self.myOrangeDict[myOrange].split(" ")[0] SazeH = self.myOrangeDict[myOrange].split(" ")[1] if SazeW == formatW and SazeH == formatH: nodeRead['format'].setValue(myOrange) Flag = False break if Flag: allFormat = nuke.formats() for eachFormat in allFormat: if eachFormat.width() == formatW and eachFormat.height() == formatH: myFormat = eachFormat.name() if myFormat != None: nodeRead['format'].setValue(myFormat) Flag = False break if Flag: while True: mySize = ('my_Size%s' % j) if mySize not in [eachFormat.name() for eachFormat in allFormat]: break else: j += 1 widthHeight = str(formatW) + " " + str(formatH) self.myOrangeDict.update({mySize:widthHeight}) square = widthHeight+" "+mySize nuke.addFormat(square) nodeRead['format'].setValue(mySize) #查找位数 num=firstFrameName.split(".")[-2] numPlaces = len('%s' % num) the_image = dirName.tail() number = lastFrameName.split(".") name = '.'.join(number[0:-2]) setData = myDirs+'/'+name+'.%'+'0%dd'%numPlaces+the_image nodeRead['file'].setValue(setData) nodeRead['origfirst'].setValue(the_firstframes) nodeRead['origlast'].setValue(the_lastframes) nodeRead['first'].setValue(the_firstframes) nodeRead['last'].setValue(the_lastframes) nodeRead['on_error'].setValue('cheeckerboard') #添加到类型字典中 self.mySeqClassDict.update({nodeRead: True}) if not imagesType in self.myImagesTClassDict.keys(): self.myImagesTClassDict.update({imagesType: [nodeRead]}) else: self.myImagesTClassDict[imagesType].append(nodeRead) # self.myClassDict.update({nodeRead:[myDir[-2], True]}) else: myDirs = '/'.join(myDir[0:-1]) mySequenceDir=myDir[-1].split('-') print myDirs num_1=mySequenceDir[0].split('_') num_2=mySequenceDir[1].split('_') for i in range(int(num_2[0])): g=str(i+1) myPath=myDirs+'/'+ num_1[0]+'_'+g+'_'+num_2[-1] self.myFindFrame(myPath, j) else: for dirtList in dirName: myPath = dirtList.path if os.path.isdir(myPath): self.myFindFrame(myPath, j)