def set_show_preferences(self, context): fields = context.as_template_fields() show_prefs = preferences.Preferences( pref_file_name="show_preferences.yaml", role=fields.get("Step"), seq_override=fields.get("Sequence"), shot_override=fields.get("Shot")) try: format_string = "{0} {1} {2}".format( show_prefs["show_settings"]["resolution"]["width"], show_prefs["show_settings"]["resolution"]["height"], SHOW_FORMAT_NAME) formats = nuke.formats() for nuke_format in formats: if nuke_format.name() == SHOW_FORMAT_NAME: nuke_format.setName('') nuke.addFormat(format_string) nuke.root().knob('format').setValue(SHOW_FORMAT_NAME) except KeyError as ke: self.parent.logger.warning( "Unable to find {} in show preferences. " "Not setting root format.".format(ke)) try: nuke.root().knob('fps').setValue( show_prefs["show_settings"]["fps"]) except KeyError as ke: self.parent.logger.warning( "Unable to find {} in show preferences. " "Not setting fps.".format(ke))
def reset_resolution(): """Set resolution to project resolution.""" project = io.find_one({"type": "project"}) p_data = project["data"] width = p_data.get("resolution_width", p_data.get("resolutionWidth")) height = p_data.get("resolution_height", p_data.get("resolutionHeight")) if not all([width, height]): missing = ", ".join(["width", "height"]) msg = "No resolution information `{0}` found for '{1}'.".format( missing, project["name"]) log.warning(msg) nuke.message(msg) return current_width = nuke.root()["format"].value().width() current_height = nuke.root()["format"].value().height() if width != current_width or height != current_height: fmt = None for f in nuke.formats(): if f.width() == width and f.height() == height: fmt = f.name() if not fmt: nuke.addFormat("{0} {1} {2}".format(int(width), int(height), project["name"])) fmt = project["name"] nuke.root()["format"].setValue(fmt)
def createNodes(source, w, h, output): #create read,merge,reformat,write global outputFormat global flag if source != '' and output != '': if getExtention(output) in filetypeList: r = nuke.nodes.Read() r.knob('file').fromUserText(source) srcReadNodes.append(r) m = nuke.nodes.Merge2() m.setInput(0, r) mergeNodes.append(m) if not settingFormat(w, h): #create new format if 0 < w <= 8192 and 0 < h <= 8192: outputFormat = str(w) + ' ' + str(h) + ' ' + 'newformat' nuke.addFormat(outputFormat) f = nuke.nodes.Reformat() f.setInput(0, m) f.knob('black_outside').setValue(True) f.knob('format').setValue(nuke.formats()[-1]) else: 'illegal format' else: f = nuke.nodes.Reformat() f.setInput(0, m) f.knob('black_outside').setValue(True) f.knob('format').setValue(outputFormat) w = nuke.nodes.Write() w.knob('file').fromUserText(outputPath) w.setInput(0, f) writeNodes.append(w) flag = flag + 1 else: print 'unknown output format' else: print 'please fill all information'
def reset_resolution(): """Set resolution to project resolution.""" project = io.find_one({"type": "project"}) try: width = project["data"].get("resolution_width", 1920) height = project["data"].get("resolution_height", 1080) except KeyError: print("No resolution information found for \"{0}\".".format( project["name"])) return current_width = nuke.root()["format"].value().width() current_height = nuke.root()["format"].value().height() if width != current_width or height != current_height: fmt = None for f in nuke.formats(): if f.width() == width and f.height() == height: fmt = f.name() if not fmt: nuke.addFormat("{0} {1} {2}".format(int(width), int(height), project["name"])) fmt = project["name"] nuke.root()["format"].setValue(fmt)
def importAsset(self, iAObj=None): start, end = HelpFunctions.getFileSequenceStartEnd(iAObj.filePath) nuke.nodePaste(iAObj.filePath % start) if iAObj.options["importSettings"]: component = ftrack.Component(iAObj.componentId) parent = component.getVersion().getAsset().getParent() # Setup fps nuke.root()['fps'].setValue(parent.get('fps')) # Setup frame range nuke.root()['first_frame'].setValue(parent.get('fstart')) nuke.root()['last_frame'].setValue(parent.get('fend')) # Setup resolution width = parent.get("width") height = parent.get("height") fmt = None for f in nuke.formats(): if f.width() == width and f.height() == height: fmt = f if fmt: nuke.root()['format'].setValue(fmt.name()) return
def settingFormat(width, height): global outputFormat for i in nuke.formats(): if width == i.width() and height == i.height(): outputFormat = i return True return False
def setOutputFormat(self,value): #change widgets editable or not if value == 'Custom': self.nameLabel.setEnabled(True) self.formatName.setEnabled(True) self.wLabel.setEnabled(True) self.formatw.setEnabled(True) self.hLabel.setEnabled(True) self.formath.setEnabled(True) else: self.nameLabel.setEnabled(False) self.formatName.setEnabled(False) self.wLabel.setEnabled(False) self.formatw.setEnabled(False) self.hLabel.setEnabled(False) self.formath.setEnabled(False) self.formatName.setText(nuke.formats()[self.formatCombo.currentIndex()].name()) self.formatw.setText(str(nuke.formats()[self.formatCombo.currentIndex()].width())) self.formath.setText(str(nuke.formats()[self.formatCombo.currentIndex()].height()))
def setUpFormat(): hasFormat = False scriptFormats = nuke.formats() for f in scriptFormats: if f.name() == 'ramshorn' and f.width() == 1280 and f.height() == 692: hasFormat = True if not hasFormat: ramshornFmt = '1280 692 ramshorn' nuke.addFormat(ramshornFmt)
def set_global_resolution(): width, height = utils.get_resolution_data() log.info("Setup project resolution: %dx%d" "" % (width, height)) root = nuke.Root() for format in nuke.formats(): if format.width() == width and format.height() == height: root["format"].setValue(format.name()) break
def initFormatList(self): try: listFormat = [] for nFormat in nuke.formats(): item = "%sx%s %s " % (nFormat.width(), nFormat.height(), nFormat.name()) listFormat.append(item) return listFormat except: return self._testData
def set_format(self, read, resolution): w, h = resolution for format in nuke.formats(): if format.width() == w and format.height() == h: try: read["format"].setValue(format.name()) except TypeError: self.log.warning("Unrecognized format") finally: break
def mosaicer(): values = getTextureNodes() if values: nodes = values['reads'] tiles = values['tilesNumber'] prefix = values['texturePrefix'] #resolution = getResolutionFromNodes(nodes) resolution = values['resolution'] tileSize = float(resolution)/float(tiles) # add format formatN = ("mosaicFormat") form = ("%s %s 1 %s" % (resolution, resolution, formatN)) nuke.addFormat(form) formatDict = {} for item in nuke.formats(): formatDict[item.name()]=item nuke.Root()['format'].setValue(formatDict[formatN]) # create background node bg = nuke.createNode('Constant', inpanel=False) bg['format'].setValue(formatN) merges = [] deselectAll() for node in nodes: node.setSelected(True) filename = os.path.basename(node['file'].value()) s, t = filename.split('_')[-3].split('s')[-1].split('t') # create reformat reformat = nuke.createNode('Reformat', inpanel=False) reformat['type'].setValue(1) reformat['box_fixed'].setValue(True) reformat['box_width'].setValue(tileSize) reformat['box_height'].setValue(tileSize) # create transform transform = nuke.createNode('Transform', inpanel=False) transform['center'].setValue([0, 0]) transform['translate'].setValue([float(s)*tileSize, float(t)*tileSize]) deselectAll() # create merge merge = nuke.createNode('Merge', inpanel=False) merge.setInput(1, transform) merge.setInput(0, bg) merges.append(merge) #deselectAll() #for m in merges: # m.setSelected(True) #nuke.createNode('Merge', inpanel=False) else: print "abort."
def resolution_init(): """ Sets the resolution on first launch. Extracting a "width" and "height" custom attributes, on the parent entity of the task. Adds a "ftrackResolutionSet" knob to the root node in Nuke, which indicates whether to set the resolution on startup. """ node = nuke.root() # Adding/Checking ftrack fps attribute resolution_set = False if "ftrackResolutionSet" in node.knobs(): resolution_set = node["ftrackResolutionSet"].getValue() else: node.addKnob(nuke.Tab_Knob("Ftrack")) knob = nuke.Boolean_Knob("ftrackResolutionSet", "Set Resolution on startup.") node.addKnob(knob) node["ftrackResolutionSet"].setValue(True) if not resolution_set: session = ftrack_api.Session() task = session.get("Task", os.environ["FTRACK_TASKID"]) width = None if "width" in task["parent"]["custom_attributes"]: width = task["parent"]["custom_attributes"]["width"] height = None if "height" in task["parent"]["custom_attributes"]: height = task["parent"]["custom_attributes"]["height"] if not width or not height: msg = "{0}: Could not find required custom attributes " msg += "\"width\" and \"height\" on {1}." print msg.format(__file__, task["parent"]["name"]) return msg = "{0}: Setting Resolution to {1}x{2}." print msg.format(__file__, width, height) fmt = None for f in nuke.formats(): if f.width() == width and f.height() == height: fmt = f if fmt: nuke.root()['format'].setValue(fmt.name()) else: fmt = "{0} {1} FtrackDefault" nuke.addFormat(fmt) nuke.root()['format'].setValue("FtrackDefault")
def find_format(resolution): mobj = re.match(r"(\d+)x(\d+)", resolution) if mobj: width = int(mobj.group(1)) height = int(mobj.group(2)) # given a resolution, find a matching format for f in nuke.formats(): if f.width() == width and f.height() == height: # found it! return f return None
def C4dRead(fileNameSeq): node = nuke.nodes.Read(xpos=0, ypos=0) lastf = int(fileNameSeq.split("-")[-1]) firstf = int(node['first'].getValue()) node['last'].setValue(lastf) fRange = [firstf, lastf] fileName = fileNameSeq.split(" ") fileName = fileName[0] node['file'].setValue(fileName) node['name'].setValue("c4dread") c4dreadFormat = node.format() c4dreadFormat.setName("C4DFormat") w = str(c4dreadFormat.width()) h = str(c4dreadFormat.height()) readFt = w + " " + h + " C4D Format" scriptFormats = nuke.formats() nuke.addFormat(readFt) nuke.root()['format'].setValue("C4D Format") return fRange
def set_resolution(self, image_format): """Sets the resolution of the current scene :param image_format: Stalker ImageFormat instance """ # try to get the format first found_format = None for f in nuke.formats(): if f.name() == image_format.name: found_format = f break if not found_format: # create a new format found_format = nuke.addFormat( "%s %s" % (image_format.width, image_format.height)) found_format.setName(image_format.name) # set the current format to that value root = self.get_root_node() root["format"].setValue("%s" % image_format.name)
def setResolution(): import helix.api.nuke.utils as nkutils import nuke show = helix.hxenv.getShow() if show: print 'Setting resolution...', formatName = '{} Format'.format(show.alias) width = show.resolution_x height = show.resolution_y overscanX = 0 # TODO: implement this as an option overscanY = 0 x = overscanX y = overscanY r = width - overscanX t = height - overscanY format = None for f in nuke.formats(): if f.name() == formatName: format = f break if format is not None: format.setWidth(width) format.setHeight(height) format.setX(x) format.setY(y) format.setR(r) format.setT(t) else: format = nuke.addFormat( '%d %d %d %d %d %d 1.0 %s' % (width, height, x, y, r, t, formatName)) nkutils.setRootKnobValue('format', format.name()) print 'Done'
#input_artist = nuke.toNode("input_artist") #input_artist["message"].setValue(options.artist) input_filename = nuke.toNode("input_filename") input_filename["message"].setValue(os.path.splitext(os.path.splitext(os.path.split(options.inputPath)[1])[0])[0]) input_date = nuke.toNode("input_date") input_date["message"].setValue(datetime.date.today().isoformat()) output_format = nuke.toNode("output_format") mobj = re.match(r"(\d+)x(\d+)", options.resolution) if mobj: width = int(mobj.group(1)) height = int(mobj.group(2)) # given a resolution, find a matching format for f in nuke.formats(): if f.width() == width and f.height() == height: # found it! output_format["format"].setValue(f) break else: parser.error("can't find matching resolution for " + options.resolution) else: parser.error("can't parse resolution: " + options.resolution) output_movie = nuke.toNode("output_movie") output_movie["file"].fromUserText(os.path.abspath(options.outputPath)) ext = os.path.splitext(options.outputPath)[1][1:] if ext == "mov": output_movie["format"].setValue("QuickTime / MOV (mov)")
def mergeCamera(self, mymodel): self.mode = mymodel #定义_source为所选的素材、_contactSheet方格 _constant黑板 _backDropStr背板、保存的摄像机字典 _source = nuke.selectedNodes('Read') self.numSelect = len(_source) _contactSheet, _constant, _backDropStr = '', '', '' _sortedCam = {} #搜索所选的内容 if len(nuke.selectedNodes('ContactSheet')): _contactSheet = nuke.selectedNodes('ContactSheet')[0] if len(nuke.selectedNodes('Constant')): _constant = nuke.selectedNodes('Constant')[0] if len(_source) == 0: nuke.message("No Read Nodes Selected...") return #以第一个素材为例,定义素材的格式_w _h #相对于nuke的节点大小_bbox, 节点的位置_pos _node = _source[0] _w = _node.knob('format').value().width() _h = _node.knob('format').value().height() _bbox = [_node.screenWidth(), _node.screenHeight()] _pos = [_node.xpos(), _node.ypos()] #常见点节点,并设置它的坐标为第一个素材的节点位置 _dot = nuke.nodes.Dot() _dot.setXYpos(_pos[0], _pos[1]) if self.numSelect <= 9: _pattern = ((-1, -2), (-0, -2), (1, -2), \ (-1, -1), (0, -1), (1, -1), \ (-1, 0), (0, 0), (1, 0)) else: _pattern = ((-3, -2), (-2, -2), (-1, -2), (0, -2), (1, -2), (2, -2), \ (-3, -1), (-2, -1), (-1, -1), (0, -1), (1, -1), (2, -1), \ (-3, 0), (-2, 0), (-1, 0), (0, 0), (1, 0), (2, 0)) #查找输出尺寸 # _format = nuke.knob("format").split() #当方格为空时创建方格,并设置它的位置 if _contactSheet == "": if self.numSelect <= 9: _contactSheet = nuke.nodes.ContactSheet( width=_w * 3, height=_h * 3, rows=3, columns=3, roworder='TopBottom').name() else: _contactSheet = nuke.nodes.ContactSheet( width=_w * 6, height=_h * 3, rows=3, columns=6, roworder='TopBottom').name() _node = nuke.toNode(_contactSheet) _node.setXYpos(_dot.xpos() + _bbox[0] * 0, _dot.ypos() + _bbox[1] * 2) #在所有的尺寸格式中,寻找跟素材一样样式,在创建黑板,并设置位置 if _constant == "": _allFormat = nuke.formats() for _eachFormat in _allFormat: if _eachFormat.width() == _w and _eachFormat.height() == _h: _constant = nuke.nodes.Constant( format=_eachFormat.name()).name() _node = nuke.toNode(_constant) #_node.setXYpos(_dot.xpos()+_bbox[0]*1,_dot.ypos()+_bbox[1]*-1) #在每个素材中记录摄像机,且记录背板的名字 for each in _source: camStr = self.checkFile(each) if camStr: _sortedCam[camStr[0]] = each if not _backDropStr: _backDropStr = camStr[1] else: each.setSelected(False) _sheetNode = nuke.toNode(_contactSheet) _conNode = nuke.toNode(_constant) if self.numSelect <= 9: for _x in range(9): _sheetNode.setInput(_x, _conNode) else: for _x in range(18): _sheetNode.setInput(_x, _conNode) #判断素材的格式 myfileFlagEXR = False myfileName = _source[0]['file'].value() myfileNameType = os.path.splitext(myfileName)[1] if myfileNameType: if myfileNameType.find('exr') >= 0: myfileFlagEXR = True myii = 0 for _k, _v in _sortedCam.iteritems(): _sourceNode = _v #查找摄像机相对应的方格通道,链接,并调整位置 if _k[0] == "_": myKey = _k[1::] else: myKey = _k #当时exr时,添加shuffle通道节点 if self.mode == 1: _sheetNode.setInput(self.num[myKey] - 1, _sourceNode) _pick = _pattern[self.num[myKey] - 1] _sourceNode.setXYpos(_bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) #当时exr时,根据需要添加shuffle通道节点 elif self.mode == 2: _pick = _pattern[self.num[myKey] - 1] _sourceNode.setXYpos(_bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) if not myfileFlagEXR: _sheetNode.setInput(self.num[myKey] - 1, _sourceNode) _sourceNode.setSelected(1) else: if myii == 0: myShuffle = nuke.nodes.Shuffle() myShuffle.setInput(0, _sourceNode) _sheetNode.setInput(self.num[myKey] - 1, myShuffle) myShuffle.setXYpos(_bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) else: self.setSelecteNone() newMyShuffle = nuke.clone(myShuffle) newMyShuffle.setInput(0, _sourceNode) _sheetNode.setInput(self.num[myKey] - 1, newMyShuffle) newMyShuffle.setXYpos( _bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) # _pick = _pattern[self.num[myKey]-1] # _sourceNode.setXYpos(_bbox[0]*_pick[0]+_dot.xpos(),_bbox[1]*_pick[1]+_dot.ypos()+20) # myShuffle.setSelected(1) # _sourceNode.setSelected(1) myii = myii + 1 _sheetNode.setSelected(1) for each in _source: each.setSelected(1) #创建背板,并设置名字, #bd = nukescripts.autoBackdrop() #bd.knob('label').setValue(_backDropStr) _sheetNode.setXYpos(_dot.xpos() + _bbox[0] * 0, _dot.ypos() + _bbox[1] * 1) if self.numSelect == 5: _conNode.setXYpos(_dot.xpos() + _bbox[0] * 1, _dot.ypos() + _bbox[1] * 1 - 50) else: _conNode.setXYpos(_dot.xpos() + _bbox[0] * 1 + 86, _dot.ypos() + _bbox[1] * 1 - 45) #删除黑板 conUsed = _conNode.dependent() if not conUsed: nuke.delete(_conNode) else: _conNode.setSelected(1) nuke.delete(_dot) bd = nukescripts.autoBackdrop() bd.knob('label').setValue(_backDropStr) myOldbdHeight = bd.knob('bdheight').value() bd.knob('bdheight').setValue(myOldbdHeight + 15)
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 mergeFYNLJCamera(self): _source = nuke.selectedNodes('Read') if len(_source) == 0: nuke.message('No Read Nodes Selected...') return #以所选的第一个素材为例,定义素材的格式_w _h _node = _source[0] #获取第一个素材在nuke中的位置 _w = _node.knob('format').value().width() _h = _node.knob('format').value().height() _bbox = [_node.screenWidth(), _node.screenHeight()] _pos = [_node.xpos(), _node.ypos()] #常见点节点,并设置它的坐标为第一个素材的节点位置 _dot = nuke.nodes.Dot() _dot.setXYpos(_pos[0], _pos[1]) _pattern = ((-2, 0), (-1, 0), (0, 0), (1, 0), (2, 0)) #保存的摄像机字典 _sortedCam = {} _constant = "" _backDropStr = "" j = 0 #在所有的尺寸格式中,寻找跟素材一样样式,在创建黑板,并设置位置 flag = True if _constant == "": _allFormat = nuke.formats() _constant = nuke.nodes.Constant() for _eachFormat in _allFormat: if _eachFormat.width() == 6000 and _eachFormat.height( ) == 1785: myFormat = _eachFormat.name() if myFormat != None: _constant['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(6000) + " " + str(1785) square = widthHeight + " " + mySize nuke.addFormat(square) _constant['format'].setValue(mySize) _node = nuke.toNode(_constant.name()) #在每个素材中记录摄像机,并记录黑板的名字 for each in _source: camStr = self.checkFile(each) if camStr: _sortedCam[camStr[0]] = each if not _backDropStr: _backDropStr = camStr[1] else: each.setSelected(False) mii = 0 Merges = {} for _k, _v in _sortedCam.iteritems(): _sourceNode = _v myKey = _k _pick = _pattern[self.num[myKey] - 1] _sourceNode.setXYpos(_bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) TransformNode = nuke.nodes.Transform() TransformNode.setXYpos( _bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos() + _bbox[1] + 10) MergeNode = nuke.nodes.Merge2() MergeNode.setXYpos( _bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos() + _bbox[1] + 40) TransformNode.setInput(0, _sourceNode) MergeNode.setInput(1, TransformNode) if self.num[myKey] == 1: TransformNode['translate'].setValue([3997, 0]) Merges.update({1: MergeNode}) elif self.num[myKey] == 2: TransformNode['translate'].setValue([1993, 0]) Merges.update({2: MergeNode}) elif self.num[myKey] == 3: TransformNode['translate'].setValue([-4, 0]) Merges.update({3: MergeNode}) elif self.num[myKey] == 4: TransformNode['translate'].setValue([2000, 0]) Merges.update({4: MergeNode}) elif self.num[myKey] == 5: TransformNode['translate'].setValue([4004, 0]) Merges.update({5: MergeNode}) i = 1 for key in Merges.keys(): if i == 1: print Merges[i] #_source[0].setInput(0, _constant) Merges[i].setInput(0, _node) else: Merges[i].setInput(0, Merges[i - 1]) i = i + 1 _node.setXYpos(_bbox[0] * _pattern[0][0] - _bbox[0] + _dot.xpos(), _bbox[1] * 1 + _dot.ypos()) nuke.delete(_dot) self.setSelecteNone() for each in _source: each.setSelected(1) _node.setSelected(1) bd = nukescripts.autoBackdrop() bd.knob('label').setValue(_backDropStr) myOldbdHeight = bd.knob('bdheight').value() bd.knob('bdheight').setValue(myOldbdHeight + 80)
input_filename = nuke.toNode("input_filename") input_filename["message"].setValue( os.path.splitext(os.path.splitext(os.path.split( options.inputPath)[1])[0])[0]) input_date = nuke.toNode("input_date") input_date["message"].setValue(datetime.date.today().isoformat()) output_format = nuke.toNode("output_format") mobj = re.match(r"(\d+)x(\d+)", options.resolution) if mobj: width = int(mobj.group(1)) height = int(mobj.group(2)) # given a resolution, find a matching format for f in nuke.formats(): if f.width() == width and f.height() == height: # found it! output_format["format"].setValue(f) break else: parser.error("can't find matching resolution for " + options.resolution) else: parser.error("can't parse resolution: " + options.resolution) output_movie = nuke.toNode("output_movie") output_movie["file"].fromUserText(os.path.abspath(options.outputPath)) ext = os.path.splitext(options.outputPath)[1][1:] if ext == "mov":
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)
def AutoProjectSettings(): print print('.............................') print('... Starting Auto Project ...') print('.............................') ####################### # Create a Dialog Box # # Input variables readFile = '/groups/cenote/BYU_anm_pipeline/production/shots/' startAt = 'Force Start at Frame 1001' exportAt = 'Export at Original Frame Range' localizer = 'Localization Policy' TCL = 'Use TCL command on Write node' saveFolder = '/groups/cenote/' scriptName = 'Script Name' addFolder = 'scripts, render' z = nuke.Panel('New comp from shot layers') z.addFilenameSearch('Read File', readFile) z.addBooleanCheckBox(startAt, 'True') z.addBooleanCheckBox(exportAt, 'False') z.addBooleanCheckBox(localizer, 'False') z.addBooleanCheckBox(TCL, 'True') z.addFilenameSearch('Save Folder', saveFolder) z.addSingleLineInput('Script Name', scriptName) z.addSingleLineInput('Additional Folders', addFolder) z.addButton('Cancel') z.addButton('OK') z.setWidth(600) result = z.show() # End of Dialog Box # ##################### if result == 0: pass # If hit 'Cancel', pass else: #files = glob.glob(readFile, recursive=True) #print(files) # Get values readFile = z.value(readFile) startAt = z.value(startAt) exportAt = z.value(exportAt) localizer = z.value(localizer) TCL = z.value(TCL) saveFolder = z.value(saveFolder) scriptName = z.value(scriptName) addFolder = z.value('Additional Folders') # Internal variables createFolder = False versionUp = False createScriptFolder = False createExportFolder = False if (readFile == ('Read File')) or ( readFile == ('') ): # If Read file keep with the original value or is empty, the process will not run print('Nothing to do here!') pass else: task = nuke.ProgressTask('Creating script...') if (saveFolder == '') or (saveFolder == 'Master Folder'): createFolder = False print print('No folder structure created ') else: ########################### # Create Folder Structure # createFolder = True shotFolder = (os.path.join(saveFolder, scriptName)) print print('Create folder structure at') print(saveFolder) try: os.mkdir(shotFolder) print print('-> Shot folder created: ' + shotFolder) task.setMessage('Creating: %s' % (shotFolder)) except: print print('-> Main folder already exist!\n%s' % (shotFolder)) if (addFolder == ''): #createFolder = False print print("--> Don't create any sub-folders") pass else: folderList = [] for i in addFolder.split(', '): folderList.append(i) # Create sub-directories for i in folderList: folderName = (os.path.join(shotFolder, i)) folderName = folderName.replace('\\', '/') task.setMessage('Creating: %s' % (folderName)) try: os.mkdir(folderName) print print('--> Created sub-directory: ' + folderName) except: print print('--> Folder already exist!\n%s' % (folderName)) versionUp = True if folderList.index(i) == 0: scriptFolder = folderName # Get the first folder name to save the Script createScriptFolder = True if folderList.index(i) == 1: exportFolder = folderName # Get the second folder name to set the Write node createExportFolder = True print print('++++++++++++++++++++++++++++++++++') # End of Folder Creator # ##################### ############### # Create Read # filelist = [readFile] if filelist != None: for f in filelist: newRead = nuke.createNode("Read", "file {" + f + "}", inpanel=True) inPoint = newRead['first'].getValue() outPoint = newRead['last'].getValue() newRead['before'].setValue('black') newRead['after'].setValue('black') newRead.hideControlPanel() inPoint = int(inPoint) outPoint = int(outPoint) print print('Read Node created: ' + newRead.name()) print('--> ' + f) task.setMessage('Creating: %s' % (newRead.name())) if localizer == True: newRead['localizationPolicy'].setValue('on') # Get Read infos width = (newRead.width()) height = (newRead.height()) frameRate = (newRead.metadata('input/frame_rate')) xPos = newRead['xpos'].getValue() yPos = newRead['ypos'].getValue() readFormat = newRead.knob('format').value().name() redAspect = False aspectRatio = (newRead.metadata('exr/pixelAspectRatio')) if aspectRatio == None: try: aspectRatio = (newRead.metadata('r3d/pixel_aspect_ratio')) redAspect = True except: aspectRatio = (newRead.metadata('input/pixel_aspect')) print('Input aspect Ratio') # End Create Read # ################### ################### # Create Timeclip # tclip = nuke.createNode('TimeClip') tclip['first'].setValue(int(inPoint)) tclip['last'].setValue(int(outPoint)) tclip['before'].setValue('black') tclip['after'].setValue('black') tclip['frame_mode'].setValue('start at') print print('Timeclip Node created: ' + tclip.name()) task.setMessage('Creating: %s' % (tclip.name())) if exportAt == True: origInPoint = inPoint origOutPoint = outPoint if startAt == True: outPoint = (outPoint - inPoint) + 1001 inPoint = 1001 tclip['frame'].setValue(str(inPoint)) tclip.setInput(0, newRead) tclip.hideControlPanel() tclip['xpos'].setValue(xPos) tclip['ypos'].setValue(yPos + 100) tclip['selected'].setValue(False) # End Timeclip # ################ ############## # Create Dot # nDot = nuke.createNode('Dot') nDot['name'].setValue('FinalOutput') nDot['label'].setValue('Final Output') nDot.setInput(0, tclip) nDot.hideControlPanel() nDot['xpos'].setValue(xPos + 34) nDot['ypos'].setValue(yPos + 650) nDot['selected'].setValue(False) # End Dot # ########### ################# # Create Viewer # v = 0 for i in nuke.allNodes(): if i.Class() in ('Viewer'): v = v + 1 if v == 0: nViewer = nuke.createNode('Viewer') nViewer.setInput(0, nDot) nViewer['xpos'].setValue(xPos + 200) nViewer['ypos'].setValue(yPos + 650) nViewer['selected'].setValue(False) if startAt == True: nuke.frame(1001) else: nuke.frame(int(inPoint)) # End Viewer # ############## #################################### # Create Backdrop for Read Session # newRead['selected'].setValue(True) sel = nuke.selectedNode() Xw = sel['xpos'].getValue() Yw = sel['ypos'].getValue() if exportAt == True: rLabel = ( '<center><img src = "' "Read.png" '" >Read File\n<font size = 1>Frame Range: %d - %d\nOriginal Frame Range: %d - %d' % ((inPoint), (outPoint), int(origInPoint), int(origOutPoint))) else: rLabel = ('<center><img src = "' "Read.png" '" >Read File\n<font size = 1>Frame Range: %s - %s' % (inPoint, outPoint)) bk = nukescripts.autoBackdrop() bk['label'].setValue(rLabel) bk['bdwidth'].setValue(500) bk['bdheight'].setValue(500) bk['xpos'].setValue(Xw - 225) bk['ypos'].setValue(Yw - 200) print print('Backdrop created: ' + bk.name()) print print('++++++++++++++++++++++++++++++++++') task.setMessage('Creating: %s' % (bk.name())) # End of create Backdrop # ########################## ########################## # Setup Project Settings # print print('Project Settings') task.setMessage('Project Settings...') sel = nuke.selectedNode() nkRoot = nuke.root() if frameRate == None: nkRoot['fps'].setValue(24) else: nkRoot['fps'].setValue(frameRate) if aspectRatio == None: aspectRatio = 1 nkRoot['first_frame'].setValue(inPoint) nkRoot['last_frame'].setValue(outPoint) nkRoot['lock_range'].setValue(True) print print('Set Frame Range to %s:%s' % (str(inPoint), str(outPoint))) if readFormat == None: newFormatName = ('%s_Resolution' % (newRead.name())) nuke.addFormat('%d %d %d %s' % (width, height, aspectRatio, newFormatName)) nkRoot['format'].setValue(newFormatName) newRead['format'].setValue(newFormatName) print print( 'Set Format to %s %sx%s, and aspect ratio to %s' % (newFormatName, str(width), str(height), str(aspectRatio))) else: for each in (nuke.formats()): if (each.name()) == readFormat: nkRoot['format'].setValue(each.name()) print print( 'Set Format to %s %sx%s, and aspect ratio to %s' % (str(each.name()), str(width), str(height), str(aspectRatio))) pass print print('++++++++++++++++++++++++++++++++++') # End of Project Settings # ########################### ################################################## # Create Timeclip to set to original plate range # if exportAt == True: newRead['selected'].setValue(False) exclip = nuke.createNode('TimeClip') exclip['first'].setValue(int(inPoint)) exclip['last'].setValue(int(outPoint)) exclip['before'].setValue('black') exclip['after'].setValue('black') exclip.hideControlPanel() exclip['xpos'].setValue(xPos) exclip['ypos'].setValue(yPos + 910) exclip.setInput(0, nDot) exclip['selected'].setValue(False) exclip['frame_mode'].setValue('start at') exclip['frame'].setValue(str(origInPoint)) task.setMessage('Creating: %s' % (exclip.name())) print print('Timeclip Node created: ' + exclip.name()) # End Timeclip Reverse # ######################## #################### #Create Write node # newRead['selected'].setValue(False) nWrite = nuke.createNode('Write') nWrite['name'].setValue('Write_Output') nWrite['channels'].setValue('rgb') nWrite['file_type'].setValue('exr') nWrite['create_directories'].setValue(True) task.setMessage('Creating: %s' % (nWrite.name())) frHash = '####' if (createExportFolder == True): if TCL == True: folderTCL = '[lindex [split [lindex [split [value root.name] /] end] .] 0]' scriptTCL = '[lindex [split [lindex [split [value root.name] /] end] .] 0].%05d.exr' writeFile = ('%s/%s/%s' % (exportFolder, folderTCL, scriptTCL)) else: writeFile = ( '%s/%s_v001/%s_v001.%s.exr' % (exportFolder, scriptName, scriptName, frHash)) nWrite['file'].setValue(writeFile) nWrite['xpos'].setValue(xPos) nWrite['ypos'].setValue(yPos + 1000) print print('Write Node created: ' + nWrite.name()) if exportAt == True: nWrite.setInput(0, exclip) else: nWrite.setInput(0, nDot) nWrite.hideControlPanel() nWrite['selected'].setValue(True) sel = nuke.selectedNode() Xw = sel['xpos'].getValue() Yw = sel['ypos'].getValue() # End Write # ############# ################################ #Create Backdrod to Write Area # if exportAt == True: wLabel = ( '<center><img src = "' "Write.png" '" >Output\n<font size = 1>Frame Range: %d - %d\nOriginal Frame Range: %d - %d' % ((inPoint), (outPoint), int(origInPoint), int(origOutPoint))) else: wLabel = ('<center><img src = "' "Write.png" '" >Output\n<font size = 1>Frame Range: %d - %d' % (inPoint, outPoint)) bk = nukescripts.autoBackdrop() bk['label'].setValue(wLabel) bk['bdwidth'].setValue(500) bk['bdheight'].setValue(400) bk['xpos'].setValue(Xw - 225) bk['ypos'].setValue(Yw - 300) task.setMessage('Creating: %s' % (bk.name())) print print('Backdrop created: ' + bk.name()) print print('++++++++++++++++++++++++++++++++++') # End Backdrop # ################ ###################################################### # Save project at first folder name from user's list # message = False version = 'v001' try: path, dirs, files = next(os.walk(scriptFolder)) if (len(files) >= 1): a = len(files) + 1 version = 'v00' + str(a) + '_avoidOverwrite' message = True except: print print('No script Folder') pass # Get name from clip clipname = os.path.basename(readFile) nameList = [] for a in clipname.split('.'): nameList.append(a) newName = nameList[0] newName = newName.replace('#', '') if (createScriptFolder == True): task.setMessage('Saving...') if scriptName == '': nukeFile = os.path.join(scriptFolder, ('%s_%s.nk' % (newName, version))) else: nukeFile = os.path.join( scriptFolder, ('%s_%s.nk' % (scriptName, version))) nukeFile = nukeFile.replace('\\', '/') if (message == True): nuke.message( 'Saved as\n%s\nto avoid overwrite other script!\nPlease, save comp with new name.' % (nukeFile)) nuke.scriptSaveAs(nukeFile) print print('Script saved at: ' + nukeFile) print print('++++++++++++++++++++++++++++++++++') print elif (createFolder == True): task.setMessage('Saving...') if scriptName == '': nukeFile = os.path.join(shotFolder, ('%s_%s.nk' % (newName, version))) else: nukeFile = os.path.join( shotFolder, ('%s_%s.nk' % (scriptName, version))) nukeFile = nukeFile.replace('\\', '/') if (message == True): nuke.message( 'Saved as\n%s\nto avoid overwrite other script!\nPlease, save comp with new name.' % (nukeFile)) nuke.scriptSaveAs(nukeFile) print print('Script saved at: ' + nukeFile) print print('++++++++++++++++++++++++++++++++++') print else: nuke.message( '<font size = "4" color = "red"><center><b>ATENTION!</b></font>\nScript unsaved! Please, do it!' ) print print('######### ATENTION! ##########') print('Script unsaved! Please, do it!') print print('++++++++++++++++++++++++++++++++++') print print('++++++++++++++++++++++++++++++++++') print('..................................') print
def mergeCamera(self,layer,_source,_bd_X,backDropStr): #获取选择的Read节点的个数 self.numSelect=len(_source) #所选择的_contactSheet方格 _constant黑板 _backDropStr背板 _contactSheet,_constant,_bd='','','' #新创建的_contactSheet方格 _constant黑板 _backDropStr背板 _contactSheet_1,_constant_1,_backDropStr='','','' #保存的摄像机字典 _sortedCam = {} _backDropStr=backDropStr.knob('label').value() #获取所选择的contactSheet方格 _constant黑板 _backDropStr背板中的信息 if len(nuke.selectedNodes('ContactSheet')): _contactSheet=nuke.selectedNodes('ContactSheet')[0] _contactSheet.setSelected(False) #获取所选择的ContactSheet的信息 conts_w=_contactSheet.knob('rows').value() conts_h=_contactSheet.knob('columns').value() conts_row=_contactSheet.knob('roworder').value() conts_width=_contactSheet.knob('width').value() conts_height=_contactSheet.knob('height').value() const_color=_contactSheet.knob('colorder').value() const_split=_contactSheet.knob('splitinputs').value() if len(nuke.selectedNodes('Constant')): _constant=nuke.selectedNodes('Constant')[0] _constant.setSelected(False) if len(nuke.selectedNodes('BackdropNode')): _bd=nuke.selectedNodes('BackdropNode')[0] _bd.setSelected(False) else: nuke.message('No BackdropNode Nodes Selected...') return #判断是否选择了Shuffle if len(nuke.selectedNodes('Shuffle')): self.flag=True else: self.flag=False #获取BackdropNode的大小 _bd_w=_bd.knob('bdwidth').value() _bd_h=_bd.knob('bdheight').value() #获取BackdropNode的位置 _bd_pos=[_bd.xpos(),_bd.ypos()] #以第一个素材为例,定义素材的格式_w,_h _node=_source[0] #素材大小 _w=_node.knob('format').value().width() _h=_node.knob('format').value().height() #素材屏幕大小 _bbox=[_node.screenWidth(),_node.screenHeight()] _pos=[_node.xpos(),_node.ypos()] #判断素材的格式是否为EXR myfileFlagEXR=False myfileName=_source[0]['file'].value() myfileNameType = os.path.splitext(myfileName)[1] if myfileNameType: if myfileNameType.find('exr')>=0: myfileFlagEXR=True #常见节点,并设置它的坐标为第一个素材的节点的位置 if not myfileFlagEXR: return _dot_bd=nuke.nodes.Dot() _dot_bd.setXYpos(_bd_pos[0]+int(_bd_w),_bd_pos[1]+int(_bd_h)) if const_split: starframes=_contactSheet.knob('startframe').value() endframes=_contactSheet.knob('endframe').value() _contactSheet_1 = nuke.nodes.ContactSheet(width=conts_width,height=conts_height,rows=conts_w,columns=conts_h,roworder=conts_row,colorder=const_color,splitinputs=True,startframe=starframes,endframe=endframes).name() else: _contactSheet_1 = nuke.nodes.ContactSheet(width=conts_width,height=conts_height,rows=conts_w,columns=conts_h,roworder=conts_row,colorder=const_color,splitinputs=False).name() _node_1 = nuke.toNode(_contactSheet_1) #在所有的尺寸格式中,寻找跟素材一样的样式,在创建黑板,并设置位置 _allFormat = nuke.formats() for _eachFormat in _allFormat: if _eachFormat.width()==_w and _eachFormat.height()==_h: _constant_1=nuke.nodes.Constant(format=_eachFormat.name()).name() _node_1=nuke.toNode(_constant_1) _sheetNode_1= nuke.toNode(_contactSheet_1) _conNode_1=nuke.toNode(_constant_1) for _x in range(18): _sheetNode_1.setInput(_x,_conNode_1) mii=0 newMyShuffle_clone=[] for each in _source: if mii==0: #创建管道 myShuffle_1=nuke.nodes.Shuffle() myShuffle_1['in'].setValue(layer) myShuffle_1['hide_input'].setValue(True) for i in range(18): if self.flag: if _contactSheet.input(i).input(0)==each: myShuffle_1.setInput(0,each) #方格与管道连接 _sheetNode_1.setInput(i,myShuffle_1) #设置管道的位置 myS_w=each.xpos()-_bd_X myS_h=each.ypos() myShuffle_1.setXYpos(_dot_bd.xpos()+myS_w+10,myS_h) break else: if _contactSheet.input(i)==each: #管道与Read节点连接 myShuffle_1.setInput(0,each) #方格与管道连接 _sheetNode_1.setInput(i,myShuffle_1) #设置管道的位置 myS_w=each.xpos()-_bd_X myS_h=each.ypos() myShuffle_1.setXYpos(_dot_bd.xpos()+myS_w+10,myS_h) break else: self.setSelecteNone() newMyShuffle_1 = nuke.clone(myShuffle_1) for i in range(18): if self.flag: if _contactSheet.input(i).input(0)==each: newMyShuffle_1.setInput(0, each) _sheetNode_1.setInput(i, newMyShuffle_1) myS_w=each.xpos()-_bd_X myS_h=each.ypos() newMyShuffle_1.setXYpos(_dot_bd.xpos()+myS_w+10,int(myS_h)) newMyShuffle_clone.append(newMyShuffle_1) break else: if _contactSheet.input(i)==each: newMyShuffle_1.setInput(0, each) _sheetNode_1.setInput(i, newMyShuffle_1) myS_w=each.xpos()-_bd_X myS_h=each.ypos() newMyShuffle_1.setXYpos(_dot_bd.xpos()+myS_w+10,int(myS_h)) newMyShuffle_clone.append(newMyShuffle_1) break mii=mii+1 for each in _source: each.setSelected(False) #创建背板,并设置名字, cs_w=_contactSheet.xpos()-_bd.xpos() cs_h=_contactSheet.ypos() _sheetNode_1.setXYpos(_dot_bd.xpos()+cs_w+10,cs_h) #_sheetNode_1.setInput(0,_contactSheet) const_w=_constant.xpos()-_bd.xpos() const_h=_constant.ypos() _conNode_1.setXYpos(_dot_bd.xpos()+const_w+10,const_h) #删除黑板 conUsed = _conNode_1.dependent() # print conUsed if not conUsed: nuke.delete(_conNode_1) else: _conNode_1.setSelected(1) nuke.delete(_dot_bd) for shuffle in newMyShuffle_clone: shuffle.setSelected(True) _sheetNode_1.setSelected(True) _conNode_1.setSelected(True) myShuffle_1.setSelected(True) newMyShuffle_1.setSelected(True) myOldbdWidth_1=backDropStr.knob('bdwidth').value() myOldbdHeight_1=backDropStr.knob('bdheight').value() bd_1 = nukescripts.autoBackdrop() bd_1.knob('label').setValue(_backDropStr+'_'+layer) #myOldbdHeight_1 = bd_1.knob('bdheight').value() #myOldbdWidth_1=bd_1.knob('bdwidth').value() bd_1.knob('bdheight').setValue(myOldbdHeight_1) bd_1.knob('bdwidth').setValue(myOldbdWidth_1) bd_1.setSelected(True)
def createNodes(self): #create read,merge,reformat,write global flag if self.sourcePath.text() != '' and self.outputPath.text() != '': if self.getExtention(self.outputPath.text()) in filetypeList: #use custom format if self.formatCombo.currentText() == 'Custom': if self.formatName.text()!='' and self.formatw.text()!='' and self.formath.text()!='': try: newWidth = int(self.formatw.text()) newHeight = int(self.formath.text()) if newWidth > 0 and newHeight > 0 and newWidth <= 8196 and newHeight <= 8196: outputFormat = self.formatw.text()+' '+self.formath.text()+' '+self.formatName.text() nuke.addFormat(outputFormat) readNode = nuke.nodes.Read() readNode['file'].fromUserText(self.sourcePath.text()) srcReadNodes.append(readNode) watermarkMergeNode = nuke.nodes.Merge2() watermarkMergeNode.setInput(0,readNode) mergeNodes.append(watermarkMergeNode) writeReformatNode = nuke.nodes.Reformat() writeReformatNode.setInput(0,watermarkMergeNode) writeReformatNode.knob('format').setValue(nuke.formats()[-1]) writeReformatNode.knob('black_outside').setValue(True) watermarkWriteNode = nuke.nodes.Write() watermarkWriteNode.setInput(0,writeReformatNode) watermarkWriteNode.knob('file').fromUserText(self.outputPath.text()) writeNodes.append(watermarkWriteNode) nuke.toNode('Viewer1').setInput(flag,watermarkWriteNode) flag = flag + 1 self.clipCombo.addItem('Clip '+str(flag)) self.clipCombo.setCurrentIndex(flag-1) renderFirst.append(readNode.knob('first').value()) renderLast.append(readNode.knob('last').value()) self.startFrame.setText(str(readNode.knob('first').value())) self.endFrame.setText(str(readNode.knob('last').value())) self.sourcePath.clear() self.outputPath.clear() self.startFrame.clear() self.endFrame.clear() else: nuke.message('should between 1-8196') except ValueError: nuke.message('width and height should be integer') else: nuke.message('should fill all information') #use standard format else: readNode = nuke.nodes.Read() readNode['file'].fromUserText(self.sourcePath.text()) srcReadNodes.append(readNode) watermarkMergeNode = nuke.nodes.Merge2() watermarkMergeNode.setInput(0,readNode) mergeNodes.append(watermarkMergeNode) writeReformatNode = nuke.nodes.Reformat() writeReformatNode.setInput(0,watermarkMergeNode) writeReformatNode.knob('format').setValue(nuke.formats()[self.formatCombo.currentIndex()]) writeReformatNode.knob('black_outside').setValue(True) watermarkWriteNode = nuke.nodes.Write() watermarkWriteNode.setInput(0,writeReformatNode) watermarkWriteNode.knob('file').fromUserText(self.outputPath.text()) writeNodes.append(watermarkWriteNode) nuke.toNode('Viewer1').setInput(flag,watermarkWriteNode) flag = flag + 1 self.clipCombo.addItem('Clip '+str(flag)) self.clipCombo.setCurrentIndex(flag-1) renderFirst.append(readNode.knob('first').value()) renderLast.append(readNode.knob('last').value()) self.startFrame.setText(str(readNode.knob('first').value())) self.endFrame.setText(str(readNode.knob('last').value())) self.sourcePath.clear() self.outputPath.clear() else: nuke.message('unknown output format') else: nuke.message('should set source and output')
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')
def mergeCams_dntg(self, sourceSels, flag, FileName): _dot = nuke.nodes.Dot() sourceSels = sorted(sourceSels, key=lambda eaNd: self.checkFile(eaNd, FileName)[0]) left_edge = min(eand.xpos() for eand in sourceSels) right_edge = max(eand.xpos() for eand in sourceSels) top_edge = min(eand.ypos() for eand in sourceSels) bottom_edge = max(eand.ypos() for eand in sourceSels) _sortedCam = {} # cleare select for i in sourceSels: i['selected'].setValue(False) transData = { "A": { "translate": [0, 0] }, "B": { "translate": [2286, 1028.5] }, "C": { "translate": [4572, 0] } } centerData = [1143, 4343.5] merge_inputPlugs = {0: 1, 1: 3, 2: 4} x_pos_v = left_edge transLst = [] for each in sourceSels: # each['selected'].setValue(True) camStr = self.checkFile(each, FileName) if not camStr: nuke.error("sutff name promeblem") _bkdrpStr = "cam{}".format(camStr[0]) each.setXYpos(x_pos_v, top_edge) ea_w = each.screenWidth() ea_h = each.screenHeight() ea_left = each.xpos() ea_right = ea_left + ea_w ea_top = each.ypos() ea_bottom = ea_top - ea_h # each.setSelected(1) bdrp = nuke.nodes.BackdropNode(xpos=ea_left - 15, bdwidth=ea_w + 30, ypos=ea_top - 35, bdheight=ea_h + 70, tile_color=int((random.random() * (16 - 10))) + 10, note_font_size=42) bdrp.setName(camStr[0]) bdrp.knob("label").setValue(_bkdrpStr) trnsnd = nuke.nodes.Transform() trnsnd['translate'].setValue([ transData[camStr[0]].values()[0][0], transData[camStr[0]].values()[0][1] ]) trnsnd['center'].setValue([centerData[0], centerData[1]]) trnsnd.setXYpos(ea_left, ea_bottom + 250) trnsnd.setInput(0, each) transLst.append(trnsnd) each.setYpos(each.ypos() + 30) x_pos_v += (ea_w + 33) MergeNode = nuke.nodes.Merge2() MergeNode.setXYpos(transLst[1].xpos(), transLst[1].ypos() + 80) for n in range(len(transLst)): MergeNode.setInput(merge_inputPlugs[n], transLst[n]) _setFormat = [ eafmt for eafmt in nuke.formats() if eafmt.width() == 6858 ] _constant = nuke.nodes.Constant(format=_setFormat[0].name()) _constant.setXYpos((MergeNode.xpos() + 200), MergeNode.ypos() - 50) _constant.knob("channels").setValue("rgb") MergeNode.setInput(0, _constant)
def mergeCamera(self, flag, mymodel, FileName): self.mode = mymodel #选择所有的节点 _source = nuke.selectedNodes('Read') self.numSelect = len(_source) # ===== add by zhangben 2018 12 12 =================for DNTG=============== if FileName == "DNTG" and flag == 3: self.mergeCams_dntg(_source, flag, FileName) return #定义_contactSheet方格 _constant黑板 _backDropStr背板、保存的摄像机字典 _contactSheet, _constant, _backDropStr = '', '', '' _sortedCam = {} #搜索所选的内容 if len(nuke.selectedNodes('ContactSheet')): _contactSheet = nuke.selectedNodes('ContactSheet')[0] if len(nuke.selectedNodes('Constant')): _constant = nuke.selectedNodes('Constant')[0] if len(_source) == 0: nuke.message('No Read Nodes Selected...') return if len(_source) != flag and (flag == 6 and flag < len(_source) and (FileName != "CPSH" or FileName != " FKBS") and FileName != "SGFC"): nuke.message( '\xe4\xbd\xa0\xe6\x89\x80\xe9\x80\x89\xe6\x8b\xa9\xe7\x9a\x84\xe7\xb4\xa0\xe6\x9d\x90\xe4\xb8\xaa\xe6\x95\xb0\xe4\xb8\x8e\xe4\xbd\xa0\xe9\x80\x89\xe6\x8b\xa9\xe7\x9a\x84\xe5\x90\x88\xe5\xb9\xb6\xe9\x80\x89\xe9\xa1\xb9\xe4\xb8\x8d\xe7\x9b\xb8\xe5\x90\x8c' ) return #以所选的第一个素材为例,定义素材的格式_w _h _node = _source[0] #获取第一个素材在nuke中的位置 _w = _node.knob('format').value().width() _h = _node.knob('format').value().height() #获取第一个素材的大小 _bbox = [_node.screenWidth(), _node.screenHeight()] _pos = [_node.xpos(), _node.ypos()] #常见点节点,并设置它的坐标为第一个素材的节点位置 _dot = nuke.nodes.Dot() _dot.setXYpos(_pos[0], _pos[1]) _pattern = '' if self.numSelect <= 3 and FileName == "": _pattern = ((-1, 0), (0, 0), (1, 0)) elif self.numSelect == 4 and FileName == "": _pattern=((-1,-1),(0,-1),(1,-1),\ (-1,0),(0,0),(1,0)) elif self.numSelect <= 6 and FileName == "CPSH": _pattern=((-2,-2),(-1,-2),(0,-2),(1,-2),\ (-2,-1),(-1,-1),(0,-1),(1,-1),\ (-2,0),(-1,0),(0,0),(1,0)) elif self.numSelect <= 6 and FileName == "FKBS": _pattern = ((-3, 0), (-2, 0), (-1, 0), (0, 0), (1, 0), (2, 0)) elif FileName == "SGFC" and flag == 5: _pattern=((-1,-2),(0,-2),(1,-2),\ (-1,-1),(0,-1),(1,-1),\ (-1,0),(0,0),(1,0)) #当方格为空时,并设置它的坐标为第一个素材的节点位置 if _contactSheet == "": if self.numSelect <= 3 and FileName == "": _contactSheet = nuke.nodes.ContactSheet( width=_w * 3, height=_h * 1, rows=1, columns=3, roworder='TopButtom').name() elif self.numSelect == 4 and FileName == "": _contactSheet = nuke.nodes.ContactSheet( width=_w * 3, height=_w * 2, rows=2, columns=3, roworder='TopButtom').name() elif self.numSelect <= 6 and FileName == "CPSH": _contactSheet = nuke.nodes.ContactSheet( width=_w * 4, height=_h * 3, rows=3, columns=4, roworder='TopButtom').name() elif self.numSelect <= 6 and FileName == "FKBS": _contactSheet = nuke.nodes.ContactSheet( width=_w * 6, height=_h, rows=1, columns=6, roworder='TopButtom').name() elif FileName == "SGFC": _contactSheet = nuke.nodes.ContactSheet( width=_w * 3, height=_h * 3, rows=3, columns=3, roworder='TopButtom').name() _node = nuke.toNode(_contactSheet) _node = _node.setXYpos(_dot.xpos() + _bbox[0] * 0, _dot.ypos() + _bbox[1] * 2) #在所有的尺寸格式中,寻找跟素材一样样式,在创建黑板,并设置位置 if _constant == "": _allFormat = nuke.formats() for _eachFormat in _allFormat: if _eachFormat.width() == _w and _eachFormat.height() == _h: _constant = nuke.nodes.Constant( format=_eachFormat.name()).name() _node = nuke.toNode(_constant) break if self.numSelect == 4 and FileName == "": myCrop = nuke.nodes.Crop() myCrop['box'].setValue([0, _w / 2, _w * 3, _w * 2]) myCrop['reformat'].setValue(True) _allFormat = nuke.formats() for _eachFormat in _allFormat: if _eachFormat.width() == _w and _eachFormat.height() == _h: _constant1 = nuke.nodes.Constant( format=_eachFormat.name()).name() _node1 = nuke.toNode(_constant1) if not _eachFormat.name(): widthHeight = str(_w) + " " + str(_h) square = widthHeight + " " + "myCrops" nuke.addFormat(square) _node1['format'].setValue("myCrops") break #在每个素材中记录摄像机,并记录黑板的名字 for each in _source: camStr = self.checkFile(each, FileName) if camStr: _sortedCam[camStr[0]] = each if not _backDropStr: _backDropStr = camStr[1] else: each.setSelected(False) _sheeNode = nuke.toNode(_contactSheet) _conNode = nuke.toNode(_constant) #根据所选的素材的个数创建ContactSheet和Constant连接的线 if self.numSelect == 3 and FileName == "": for _x in range(9): _sheeNode.setInput(_x, _conNode) else: for _x in range(18): _sheeNode.setInput(_x, _conNode) if self.numSelect == 4 and FileName == "": myCrop.setInput(0, _sheeNode) #判断素材的格式 myfileFlagEXR = False #查询第一个素材的路径 myfileName = _source[0]['file'].value() #获取素材的格式 myfileNameType = os.path.splitext(myfileName)[1] if myfileNameType: if myfileNameType.find('exr') >= 0: myfileFlagEXR = True myii = 0 myMer = 0 for _k, _v in _sortedCam.iteritems(): #print _k #print _v _sourceNode = _v #查找摄像机对应的方格通道,链接,并调整位置 if _k[0] == "_": myKey = _k[1::] else: myKey = _k #print myKey #当时exr时,添加shuffle通道节点 if self.mode == 1: if self.numSelect == 3 and FileName == "": _sheeNode.setInput(self.num[myKey] - 1, _sourceNode) _pick = _pattern[self.num[myKey] - 1] #设置素材的在nuke中的位置 _sourceNode.setXYpos(_bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) #FKBS特殊的比例相机 elif self.numSelect == 4 and FileName == "": if _sourceNode.knob('format').value().height( ) == _sourceNode.knob('format').value().width() / 2: _pick = _pattern[self.num4[myKey] - 1] if myMer == 0: TransformNode = nuke.nodes.Transform() MergeNode = nuke.nodes.Merge2() MergeNode.setInput(1, TransformNode) TransformNode['translate'].setValue([ 0, _sourceNode.knob('format').value().height() ]) TransformNode.setInput(0, _sourceNode) _sheeNode.setInput(self.num4[myKey] - 1, MergeNode) MergeNode.setInput(0, _node1) MergeNode.setXYpos( _bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) TransformNode.setXYpos( _bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) _sourceNode.setXYpos( _bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) else: TransformNode = nuke.nodes.Transform() self.setSelecteNone() newMergeNode = nuke.clone(MergeNode) newMergeNode.setInput(1, TransformNode) TransformNode['translate'].setValue([ 0, _sourceNode.knob('format').value().height() ]) TransformNode.setInput(0, _sourceNode) _sheeNode.setInput(self.num4[myKey] - 1, newMergeNode) newMergeNode.setInput(0, _node1) newMergeNode.setXYpos( _bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) TransformNode.setXYpos( _bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) _sourceNode.setXYpos( _bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) myMer = myMer + 1 else: _sheeNode.setInput(self.num4[myKey] - 1, _sourceNode) _pick = _pattern[self.num4[myKey] - 1] _sourceNode.setXYpos(_bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) elif self.numSelect <= 6 and FileName == "CPSH": # print myKey _sheeNode.setInput(self.num6[myKey] - 1, _sourceNode) _pick = _pattern[self.num6[myKey] - 1] _sourceNode.setXYpos(_bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) elif self.numSelect <= 6 and FileName == "FKBS": # print myKey # print self.FKBSNum6[myKey] # print _pattern _pattern[self.FKBSNum6[myKey] - 1] _sheeNode.setInput(self.FKBSNum6[myKey] - 1, _sourceNode) _pick = _pattern[self.FKBSNum6[myKey] - 1] _sourceNode.setXYpos(_bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) if FileName == "SGFC": _sheeNode.setInput(self.SGFCNum5[myKey] - 1, _sourceNode) _pick = _pattern[self.SGFCNum5[myKey] - 1] #设置素材的在nuke中的位置 _sourceNode.setXYpos(_bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) #当时exr时,根据需要添加shuffle通道节点 elif self.mode == 2: if self.numSelect == 3 and FileName == "": _pick = _pattern[self.num[myKey] - 1] _sourceNode.setXYpos(_bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) if not myfileFlagEXR: _sheeNode.setInput(self.num[myKey] - 1, _sourceNode) _sourceNode.setSelected(1) else: if myii == 0: myShuffle = nuke.nodes.Shuffle() myShuffle.setInput(0, _sourceNode) _sheeNode.setInput(self.num[myKey] - 1, myShuffle) myShuffle.setXYpos( _bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) else: self.setSelecteNone() newMyShuffle = nuke.clone(myShuffle) newMyShuffle.setInput(0, _sourceNode) _sheeNode.setInput(self.num[myKey] - 1, newMyShuffle) newMyShuffle.setXYpos( _bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) #FKBS特殊的比例相机 elif self.numSelect == 4 and FileName == "": _pick = _pattern[self.num4[myKey] - 1] _sourceNode.setXYpos(_bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) if not myfileFlagEXR: if _sourceNode.knob('format').value().height( ) == _sourceNode.knob('format').value().width() / 2: if myMer == 0: TransformNode = nuke.nodes.Transform() MergeNode = nuke.nodes.Merge2() MergeNode.setInput(1, TransformNode) TransformNode['translate'].setValue([ 0, _sourceNode.knob( 'format').value().height() ]) TransformNode.setInput(0, _sourceNode) _sheeNode.setInput(self.num4[myKey] - 1, MergeNode) MergeNode.setInput(0, _node1) MergeNode.setXYpos( _bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) TransformNode.setXYpos( _bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) myShuffle.setXYpos( _bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) _sourceNode.setSelected(1) else: TransformNode = nuke.nodes.Transform() self.setSelecteNone() newMergeNode = nuke.clone(MergeNode) newMergeNode.setInput(1, TransformNode) TransformNode['translate'].setValue([ 0, _sourceNode.knob( 'format').value().height() ]) TransformNode.setInput(0, _sourceNode) _sheeNode.setInput(self.num4[myKey] - 1, newMergeNode) newMergeNode.setInput(0, _node1) newMergeNode.setXYpos( _bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) TransformNode.setXYpos( _bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) myShuffle.setXYpos( _bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) _sourceNode.setSelected(1) myMer = myMer + 1 else: _sheeNode.setInput(self.num4[myKey] - 1, _sourceNode) _pick = _pattern[self.num4[myKey] - 1] _sourceNode.setXYpos( _bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) else: if myii == 0: if _sourceNode.knob('format').value().height( ) == _sourceNode.knob( 'format').value().width() / 2: if myMer == 0: TransformNode = nuke.nodes.Transform() MergeNode = nuke.nodes.Merge2() MergeNode.setInput(1, TransformNode) TransformNode['translate'].setValue([ 0, _sourceNode.knob( 'format').value().height() ]) myShuffle = nuke.nodes.Shuffle() TransformNode.setInput(0, _sourceNode) myShuffle.setInput(0, MergeNode) _sheeNode.setInput(self.num4[myKey] - 1, myShuffle) MergeNode.setInput(0, _node1) MergeNode.setXYpos( _bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) TransformNode.setXYpos( _bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) myShuffle.setXYpos( _bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) else: TransformNode = nuke.nodes.Transform() self.setSelecteNone() newMergeNode = nuke.clone(MergeNode) newMergeNode.setInput(1, TransformNode) TransformNode['translate'].setValue([ 0, _sourceNode.knob( 'format').value().height() ]) TransformNode.setInput(0, _sourceNode) myShuffle = nuke.nodes.Shuffle() myShuffle.setInput(0, newMergeNode) _sheeNode.setInput(self.num4[myKey] - 1, myShuffle) newMergeNode.setInput(0, _node1) newMergeNode.setXYpos( _bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) TransformNode.setXYpos( _bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) myShuffle.setXYpos( _bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) _sourceNode.setSelected(1) else: myShuffle = nuke.nodes.Shuffle() myShuffle.setInput(0, _sourceNode) _sheeNode.setInput(self.num4[myKey] - 1, myShuffle) myShuffle.setXYpos( _bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) else: if _sourceNode.knob('format').value().height( ) == _sourceNode.knob( 'format').value().width() / 2: if myMer == 0: TransformNode = nuke.nodes.Transform() MergeNode = nuke.nodes.Merge2() MergeNode.setInput(1, TransformNode) TransformNode['translate'].setValue([ 0, _sourceNode.knob( 'format').value().height() ]) newMyShuffle = nuke.clone(myShuffle) TransformNode.setInput(0, _sourceNode) newMyShuffle.setInput(0, MergeNode) _sheeNode.setInput(self.num4[myKey] - 1, newMyShuffle) MergeNode.setInput(0, _node1) MergeNode.setXYpos( _bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) TransformNode.setXYpos( _bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) newMyShuffle.setXYpos( _bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) else: TransformNode = nuke.nodes.Transform() self.setSelecteNone() newMergeNode = nuke.clone(MergeNode) newMergeNode.setInput(1, TransformNode) TransformNode['translate'].setValue([ 0, _sourceNode.knob( 'format').value().height() ]) TransformNode.setInput(0, _sourceNode) newMyShuffle = nuke.clone(myShuffle) myShuffle.setInput(0, newMyShuffle) _sheeNode.setInput(self.num4[myKey] - 1, newMyShuffle) newMergeNode.setInput(0, _node1) newMergeNode.setXYpos( _bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) TransformNode.setXYpos( _bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) newMyShuffle.setXYpos( _bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) _sourceNode.setSelected(1) else: self.setSelecteNone() newMyShuffle = nuke.clone(myShuffle) newMyShuffle.setInput(0, _sourceNode) _sheeNode.setInput(self.num4[myKey] - 1, newMyShuffle) newMyShuffle.setXYpos( _bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) elif self.numSelect <= 6 and FileName == "CPSH": _pick = _pattern[self.num6[myKey] - 1] _sourceNode.setXYpos(_bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) if not myfileFlagEXR: _sheeNode.setInput(self.num6[myKey] - 1, _sourceNode) _sourceNode.setSelected(1) else: if myii == 0: myShuffle = nuke.nodes.Shuffle() myShuffle.setInput(0, _sourceNode) _sheeNode.setInput(self.num6[myKey] - 1, myShuffle) myShuffle.setXYpos( _bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) else: self.setSelecteNone() newMyShuffle = nuke.clone(myShuffle) newMyShuffle.setInput(0, _sourceNode) _sheeNode.setInput(self.num6[myKey] - 1, newMyShuffle) newMyShuffle.setXYpos( _bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) elif self.numSelect <= 6 and FileName == 'FKBS': _pick = _pattern[self.FKBSNum6[myKey] - 1] _sourceNode.setXYpos(_bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) if not myfileFlagEXR: _sheeNode.setInput(self.FKBSNum6[myKey] - 1, _sourceNode) _sourceNode.setSelected(1) else: if myii == 0: myShuffle = nuke.nodes.Shuffle() myShuffle.setInput(0, _sourceNode) _sheeNode.setInput(self.FKBSNum6[myKey] - 1, myShuffle) myShuffle.setXYpos( _bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) else: self.setSelecteNone() newMyShuffle = nuke.clone(myShuffle) newMyShuffle.setInput(0, _sourceNode) _sheeNode.setInput(self.FKBSNum6[myKey] - 1, newMyShuffle) newMyShuffle.setXYpos( _bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) elif FileName == 'SGFC': _pick = _pattern[self.SGFCNum5[myKey] - 1] _sourceNode.setXYpos(_bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) if not myfileFlagEXR: _sheeNode.setInput(self.SGFCNum5[myKey] - 1, _sourceNode) _sourceNode.setSelected(1) else: if myii == 0: myShuffle = nuke.nodes.Shuffle() myShuffle.setInput(0, _sourceNode) _sheeNode.setInput(self.SGFCNum5[myKey] - 1, myShuffle) myShuffle.setXYpos( _bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) else: self.setSelecteNone() newMyShuffle = nuke.clone(myShuffle) newMyShuffle.setInput(0, _sourceNode) _sheeNode.setInput(self.SGFCNum5[myKey] - 1, newMyShuffle) newMyShuffle.setXYpos( _bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) myii = myii + 1 _sheeNode.setSelected(1) for each in _source: each.setSelected(1) if self.numSelect == 3 and FileName == "": _sheeNode.setXYpos(_dot.xpos() + _bbox[0] * 0, _dot.ypos() + _bbox[1] * 2 - 30) _conNode.setXYpos(_dot.xpos() + _bbox[0] * 1, _dot.ypos() + _bbox[1] * 1 - 10) elif self.numSelect == 4 and FileName == "": _sheeNode.setXYpos(_dot.xpos() + _bbox[0] * 0, _dot.ypos() + _bbox[1] * 1) _conNode.setXYpos(_dot.xpos() + _bbox[0] * 1, _dot.ypos() + _bbox[1] * 1 - 10) _node1.setXYpos(_dot.xpos() - _bbox[0] * 1, _dot.ypos() + _bbox[1] * 1 - 10) myCrop.setXYpos(_dot.xpos() + _bbox[0] * 0, _dot.ypos() + _bbox[1] * 1 + 30) elif self.numSelect <= 6 and FileName == "CPSH": _sheeNode.setXYpos(_dot.xpos() + _bbox[0] * 0 - 45, _dot.ypos() + _bbox[1] * 1) _conNode.setXYpos(_dot.xpos() + 10, _dot.ypos() + 10) elif self.numSelect <= 6 and FileName == 'FKBS': _sheeNode.setXYpos(_dot.xpos() + _bbox[0] * 0 - 45, _dot.ypos() + _bbox[1] * 2 - 30) _conNode.setXYpos(_dot.xpos() + _bbox[0] * 1, _dot.ypos() + _bbox[1] * 1 - 10) elif FileName == 'SGFC': _sheeNode.setXYpos(_dot.xpos() + _bbox[0] * 0, _dot.ypos() + _bbox[1] * 2 - 30) _conNode.setXYpos(_dot.xpos() + _bbox[0] * 1, _dot.ypos() + _bbox[1] * 1 - 10) #if self.numSelect==3: #_conNode.setXYpos(_dot.xpos()+_bbox[0]*1,_dot.ypos()+_bbox[1]*1-10) #删除黑板 conUsed = _conNode.dependent() if not conUsed: nuke.delete(_conNode) else: _conNode.setSelected(1) if self.numSelect == 4 and FileName == "": _node1.setSelected(1) myCrop.setSelected(1) nuke.delete(_dot) bd = nukescripts.autoBackdrop() bd.knob('label').setValue(_backDropStr) myOldbdHeight = bd.knob('bdheight').value() bd.knob('bdheight').setValue(myOldbdHeight + 30)
def bakeIt(node, filePath, fileSize, fileType, outcolorspace, framerange, connectToObj, alpha, antialiasing, samples, shutter): if fileSize == '1K': formatN = ("bakeUV_1K") form = ("1024 1024 1 %s" % (formatN)) nuke.addFormat(form) formatDict = {} for item in nuke.formats(): formatDict[item.name()]=item nuke.Root()['format'].setValue(formatDict[formatN]) if fileSize == '2K': formatN = ("bakeUV_2K") form = ("2048 2048 1 %s" % (formatN)) nuke.addFormat(form) formatDict = {} for item in nuke.formats(): formatDict[item.name()]=item nuke.Root()['format'].setValue(formatDict[formatN]) if fileSize == '4K': formatN = ("bakeUV_4K") form = ("4096 4096 1 %s" % (formatN)) nuke.addFormat(form) formatDict = {} for item in nuke.formats(): formatDict[item.name()]=item nuke.Root()['format'].setValue(formatDict[formatN]) if fileSize == '8K': formatN = ("bakeUV_8K") form = ("8192 8192 1 %s" % (formatN)) nuke.addFormat(form) formatDict = {} for item in nuke.formats(): formatDict[item.name()]=item nuke.Root()['format'].setValue(formatDict[formatN]) selectReplace(node) scanlineR = nuke.createNode('ScanlineRender', inpanel = False) scanlineR['name'].setValue("Scanline_"+node.name()+"_bake") scanlineR['projection_mode'].setValue('uv') scanlineR['antialiasing'].setValue(antialiasing) scanlineR['samples'].setValue(samples) scanlineR['shutter'].setValue(shutter) deselectAll() reformatBake = nuke.createNode('Reformat', inpanel = False) reformatBake['name'].setValue("reformat_"+node.name()+"_bake") reformatBake['format'].setValue("bakeUV_"+fileSize) deselectAll() scanlineR.setInput(0, reformatBake) selectReplace(scanlineR) mpcCol = nuke.createNode('MPC_ColIO_!MPC_COLIO_VERSION!', inpanel = False) mpcCol['inspace'].setValue('Linear') mpcCol['output_space'].setValue(outcolorspace) writeNode = nuke.createNode('Write', inpanel = False) try: writeNode['views'].setValue('left') except: pass writeNode['file_type'].setValue(fileType) writeNode['name'].setValue("write_"+node.name()+"_bake") writeNode['raw'].setValue(True) try: startF = int(framerange.split("-")[0]) endF = int(framerange.split("-")[1]) if startF == endF: writeNode['file'].setValue(filePath+node.name()+"_COL."+fileType) else: writeNode['file'].setValue(filePath+node.name()+"_COL.%04d."+fileType) except: startF = int(framerange) endF = int(framerange) writeNode['file'].setValue(filePath+node.name()+"_COL."+fileType) if alpha == 1: writeNode['channels'].setValue('rgba') nuke.execute(writeNode, startF, endF) deselectAll() selectAdd(scanlineR) selectAdd(reformatBake) selectAdd(mpcCol) selectAdd(writeNode) nukescripts.node_delete() deselectAll() deselectAll() readUV = nuke.createNode('Read', inpanel = False) readUV['name'].setValue("Read_"+node.name()+"_baked") readUV['file'].setValue(filePath+node.name()+"_COL."+fileType) readUV['raw'].setValue(True) lastNode = nuke.createNode('MPC_ColIO_'+MPC_colio, inpanel = False) lastNode['inspace'].setValue('Linear') lastNode['output_space'].setValue(outcolorspace) if alpha: lastNode = nuke.createNode('Premult', inpanel = False) if connectToObj: node.setInput(0, lastNode)
def FKBSMergCam(self, mode): self.mode = mode #选择所有的节点 _source = nuke.selectedNodes('Read') self.numSelect = len(_source) #定义_contactSheet方格 _constant黑板 _backDropStr背板、保存的摄像机字典 _contactSheet, _constant, _backDropStr, _contactSheet1, _constant1, _backDropStr1 = '', '', '', '', '', '' _sortedCam = {} #搜索所选的内容 if len(nuke.selectedNodes('ContactSheet')): nuke.message('ContactSheet Nodes Not Can Selected...') return if len(nuke.selectedNodes('Constant')): nuke.message('ContactSheet Nodes Not Can Selected...') return if len(_source) == 0: nuke.message('No Read Nodes Selected...') return #以所选的第一个素材为例,定义素材的格式_w _h _node = _source[0] #获取第一个素材在nuke中的位置 _w = _node.knob('format').value().width() _h = _node.knob('format').value().height() #获取第一个素材的大小 _bbox = [_node.screenWidth(), _node.screenHeight()] _pos = [_node.xpos(), _node.ypos()] #常见点节点,并设置它的坐标为第一个素材的节点位置 _dot = nuke.nodes.Dot() _dot.setXYpos(_pos[0], _pos[1]) _pattern = ((-6, 0), (-5, 0), (-4, 0), (-3, 0), (-2, 0), (-1, 0), (1, 0), (2, 0), (3, 0), (4, 0), (5, 0), (6, 0)) _contactSheet = nuke.nodes.ContactSheet(width=_w * self.numSelect / 2, height=_h, rows=1, columns=self.numSelect / 2, roworder='TopBottom').name() _contactSheet1 = nuke.nodes.ContactSheet(width=_w * self.numSelect / 2, height=_h, rows=1, columns=self.numSelect / 2, roworder='TopBottom').name() #在所有的尺寸格式中,寻找跟素材一样样式,在创建黑板,并设置位置 if _constant == "": _allFormat = nuke.formats() for _eachFormat in _allFormat: if _eachFormat.width() == _w and _eachFormat.height() == _h: _constant = nuke.nodes.Constant( format=_eachFormat.name()).name() _constant1 = nuke.nodes.Constant( format=_eachFormat.name()).name() _node = nuke.toNode(_constant) _node1 = nuke.toNode(_constant1) break #在每个素材中记录摄像机,并记录黑板的名字 for each in _source: camStr = self.checkFile(each) if camStr: _sortedCam[camStr[0]] = each if not _backDropStr: _backDropStr = camStr[1] else: each.setSelected(False) _sheeNode = nuke.toNode(_contactSheet) _sheeNode1 = nuke.toNode(_contactSheet1) _conNode = nuke.toNode(_constant) _conNode1 = nuke.toNode(_constant1) for _x in range(18): _sheeNode.setInput(_x, _conNode) _sheeNode1.setInput(_x, _conNode1) #判断素材的格式 myfileFlagEXR = False #查询第一个素材的路径 myfileName = _source[0]['file'].value() #获取素材的格式 myfileNameType = os.path.splitext(myfileName)[1] if myfileNameType: if myfileNameType.find('exr') >= 0: myfileFlagEXR = True MergCamL = [] MergCamR = [] myii = 0 myii1 = 0 for _k, _v in _sortedCam.iteritems(): #print _k #print _v _sourceNode = _v myKey = _k if self.mode == 1: if self.num[myKey] < 7: _sheeNode.setInput(self.num[myKey] - 1, _sourceNode) _pick = _pattern[self.num[myKey] - 1] #设置素材的在nuke中的位置 _sourceNode.setXYpos(_bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) MergCamL.append(_sourceNode) else: _sheeNode1.setInput(self.num[myKey] - 7, _sourceNode) _pick1 = _pattern[self.num[myKey] - 1] #设置素材的在nuke的位置 _sourceNode.setXYpos(_bbox[0] * _pick1[0] + _dot.xpos(), _bbox[1] * _pick1[1] + _dot.ypos()) MergCamR.append(_sourceNode) elif self.mode == 2: if not myfileFlagEXR: if self.num[myKey] < 7: _sheeNode.setInput(self.num[myKey] - 1, _sourceNode) _pick = _pattern[self.num[myKey] - 1] #设置素材的在nuke中的位置 _sourceNode.setXYpos(_bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) MergCamL.append(_sourceNode) else: _sheeNode1.setInput(self.num[myKey] - 7, _sourceNode) _pick1 = _pattern[self.num[myKey] - 1] #设置素材的在nuke的位置 _sourceNode.setXYpos( _bbox[0] * _pick1[0] + _dot.xpos(), _bbox[1] * _pick1[1] + _dot.ypos()) MergCamR.append(_sourceNode) else: if self.num[myKey] < 7: if myii == 0: myShuffle = nuke.nodes.Shuffle() myShuffle.setInput(0, _sourceNode) _pick = _pattern[self.num[myKey] - 1] _sheeNode.setInput(self.num[myKey] - 1, myShuffle) _sourceNode.setXYpos( _bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) myShuffle.setXYpos( _bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) else: self.setSelecteNone() newMyShuffle = nuke.clone(myShuffle) newMyShuffle.setInput(0, _sourceNode) _pick = _pattern[self.num[myKey] - 1] _sheeNode.setInput(self.num[myKey] - 1, newMyShuffle) _sourceNode.setXYpos( _bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) newMyShuffle.setXYpos( _bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) MergCamL.append(_sourceNode) myii = myii + 1 else: if myii1 == 0: myShuffle1 = nuke.nodes.Shuffle() myShuffle1.setInput(0, _sourceNode) _pick1 = _pattern[self.num[myKey] - 1] _sheeNode1.setInput(self.num[myKey] - 7, myShuffle1) _sourceNode.setXYpos( _bbox[0] * _pick1[0] + _dot.xpos(), _bbox[1] * _pick1[1] + _dot.ypos()) myShuffle1.setXYpos( _bbox[0] * _pick1[0] + _dot.xpos(), _bbox[1] * _pick1[1] + _dot.ypos()) else: self.setSelecteNone() newMyShuffle1 = nuke.clone(myShuffle1) newMyShuffle1.setInput(0, _sourceNode) _pick1 = _pattern[self.num[myKey] - 1] _sheeNode1.setInput(self.num[myKey] - 7, newMyShuffle1) _sourceNode.setXYpos( _bbox[0] * _pick1[0] + _dot.xpos(), _bbox[1] * _pick1[1] + _dot.ypos()) newMyShuffle1.setXYpos( _bbox[0] * _pick1[0] + _dot.xpos(), _bbox[1] * _pick1[1] + _dot.ypos()) MergCamR.append(_sourceNode) myii1 = myii1 + 1 self.setSelecteNone() for each in MergCamL: each.setSelected(1) _sheeNode.setXYpos(_dot.xpos() - _bbox[0] * 3 - _bbox[0] / 2, _dot.ypos() + _bbox[1] * 2 - 30) _conNode.setXYpos(_dot.xpos() - _bbox[0] * 2, _dot.ypos() + _bbox[1] * 1 - 10) #删除黑板 conUsed = _conNode.dependent() if not conUsed: nuke.delete(_conNode) else: _conNode.setSelected(1) _sheeNode.setSelected(1) bd = nukescripts.autoBackdrop() bd.knob('label').setValue(_backDropStr) myOldbdHeight = bd.knob('bdheight').value() bd.knob('bdheight').setValue(myOldbdHeight + 15) self.setSelecteNone() for each in MergCamR: each.setSelected(1) _sheeNode1.setXYpos(_dot.xpos() + _bbox[0] * 3 + _bbox[0] / 2, _dot.ypos() + _bbox[1] * 2 - 30) _conNode1.setXYpos(_dot.xpos() + _bbox[0] * 5, _dot.ypos() + _bbox[1] * 1 - 10) _conNode1.setSelected(1) _sheeNode1.setSelected(1) nuke.delete(_dot) bd1 = nukescripts.autoBackdrop() bd1.knob('label').setValue(_backDropStr) myOldbdHeight = bd1.knob('bdheight').value() bd1.knob('bdheight').setValue(myOldbdHeight + 15)
def mergeCams_dntg(self, sourceSels, flag, FileName): if sourceSels == None: sourceSels = nuke.selectedNodes('Read') numSelect = len(sourceSels) _dot = nuke.nodes.Dot() sourceSels = sorted(sourceSels, key=lambda eaNd: self.checkFile(eaNd, FileName)[0]) if not self.checkFile(sourceSels[0], FileName)[0]: sourceSels = sorted( sourceSels, key=lambda eaNd: self.__class__.checkFile4ef(eaNd)[0]) _dot.setXYpos(sourceSels[0].xpos(), sourceSels[0].ypos()) left_edge = _dot.xpos() # min(eand.xpos() for eand in sourceSels) top_edge = _dot.ypos() # min(eand.ypos() for eand in sourceSels) _sortedCam = {} # cleare select for i in sourceSels: i['selected'].setValue(False) transData = self.calculate_data(sourceSels) centerData = [1143, 4343.5] merge_inputPlugs = {0: 1, 1: 3, 2: 4} x_pos_v = left_edge transLst = [] rndlyer = [] rndCam = [] totalwidth = 0 for each in sourceSels: # each['selected'].setValue(True) camStr = self.checkFile(each, FileName) if camStr[0] == None: camStr = self.__class__.checkFile4ef(each) rndlyer.append( self.__class__.stuff_info(each, True)["rndLayer"]) rndCam.append(self.__class__.stuff_info(each, True)["rndCam"]) else: rndlyer.append(self.__class__.stuff_info(each)["rndLayer"]) rndCam.append(self.__class__.stuff_info(each)["rndCam"]) if not camStr: nuke.error("sutff name promeblem") each.setXYpos(x_pos_v, top_edge) ea_w = each.screenWidth() ea_h = each.screenHeight() ea_left = each.xpos() ea_top = each.ypos() ea_bottom = ea_top - ea_h totalwidth += ea_w trnsnd = nuke.nodes.Transform() trnsnd['translate'].setValue( [transData[camStr[0]][0], transData[camStr[0]][1]]) trnsnd['center'].setValue([centerData[0], centerData[1]]) trnsnd.setXYpos(ea_left, ea_bottom + 180) trnsnd.setInput(0, each) transLst.append(trnsnd) x_pos_v += (ea_w + 33) MergeNode = nuke.nodes.Merge2() MergeNode.setXYpos(transLst[1].xpos(), transLst[1].ypos() + 80) for n in range(len(transLst)): MergeNode.setInput(merge_inputPlugs[n], transLst[n]) _setFormat = [ eafmt for eafmt in nuke.formats() if eafmt.width() == transData['Cons'][0] ] if not len(_setFormat): dntgfmt = "{:d} {:d} DNTGEF MergCams".format( transData['Cons'][0], transData['Cons'][1]) addfmg = nuke.addFormat(dntgfmt) _constant = nuke.nodes.Constant(format=addfmg.name()) else: _constant = nuke.nodes.Constant(format=_setFormat[0].name()) _constant.setXYpos((MergeNode.xpos() + 160), MergeNode.ypos() - 50) _constant.knob("channels").setValue("rgb") MergeNode.setInput(0, _constant) rndlyer = [ rndlyer[n] for n in range(len(rndlyer)) if rndlyer[n] not in rndlyer[:n] ] if len(rndlyer) != 1: self.__class__.warn_box( "Please selecte the stuffs those in the same render layer") rndCam = [ rndCam[n] for n in range(len(rndCam)) if rndCam[n] not in rndCam[:n] ] if len(rndlyer) != 1: self.__class__.warn_box( "Please selecte the stuffs those in the same side camera") bdrp = nuke.nodes.BackdropNode( xpos=(_dot.xpos() - 15), bdwidth=totalwidth + 160, ypos=(_dot.ypos() - 75), bdheight=(MergeNode.ypos() - top_edge) + 130, tile_color=int((random.random() * (16 - 10))) + 10, note_font_size=45) camsDict = {'l': 'left', 'r': 'right', 'L': 'Left', 'R': 'Right'} cam_nm = re.search('[lr]', rndCam[0], re.I).group() drpName = "camera {} {}".format(camsDict[cam_nm], rndlyer[0]) bdrp.setName(drpName) drp_lab = "{} : {}".format(camsDict[cam_nm], rndlyer[0]) bdrp.knob("label").setValue(drp_lab) nuke.delete(_dot) nknd = each
def oldMergeCamera(self): #定义_source为所选的素材、_contactSheet方格 _constant黑板 _backDropStr背板、保存的摄像机字典 _source = nuke.selectedNodes('Read') #self.numSelect = len(_source) _contactSheet_L, _contactSheet_R, _constant_L, _constant_R, _backDropStr_L, _backDropStr_R = '', '', '', '', '', '' _sortedCamL = {} _sortedCamR = {} if len(_source) == 0: nuke.message("No Read Nodes Selected...") return for each in _source: camStr = self.checkFile(each) if camStr: if "L_" in camStr[0]: _sortedCamL[camStr[0]] = each if not _backDropStr_L: _backDropStr_L = camStr[1] elif "R_" in camStr[0]: _sortedCamR[camStr[0]] = each if not _backDropStr_R: _backDropStr_R = camStr[1] else: each.setSelected(False) #以第一个素材为例,定义素材的格式_w _h #相对于nuke的节点大小_bbox, 节点的位置_pos _node = _source[0] _w = _node.knob('format').value().width() _h = _node.knob('format').value().height() _bbox = [_node.screenWidth(), _node.screenHeight()] _pos = [_node.xpos(), _node.ypos()] #常见点节点,并设置它的坐标为第一个素材的节点位置 _dot = nuke.nodes.Dot() _dot.setXYpos(_pos[0], _pos[1]) if len(_sortedCamL) <= 3: _patternL = ((-1, 0), (0, 0), (1, 0)) if len(_sortedCamR) <= 3: _patternR = ((2, 0), (3, 0), (4, 0)) if _contactSheet_L == "": if len(_sortedCamL) <= 3: _contactSheet_L = nuke.nodes.ContactSheet( width=_w * 3, height=_h, rows=1, columns=3, roworder='TopBottom').name() if _contactSheet_R == "": if len(_sortedCamR) <= 3: _contactSheet_R = nuke.nodes.ContactSheet( width=_w * 3, height=_h, rows=1, columns=3, roworder='TopBottom').name() _node_L = nuke.toNode(_contactSheet_L) _node_L.setXYpos(_dot.xpos() + _bbox[0] * 0, _dot.ypos() + _bbox[1] * 2) _node_R = nuke.toNode(_contactSheet_R) _node_R.setXYpos(_dot.xpos() + _bbox[0] * 1, _dot.ypos() + _bbox[1] * 2) #在所有的尺寸格式中,寻找跟素材一样样式,在创建黑板,并设置位置 if _constant_L == "" and _constant_R == "": _allFormat = nuke.formats() for _eachFormat in _allFormat: if _eachFormat.width() == _w and _eachFormat.height() == _h: _constant_L = nuke.nodes.Constant( format=_eachFormat.name()).name() _node_L = nuke.toNode(_constant_L) _constant_R = nuke.nodes.Constant( format=_eachFormat.name()).name() _nod_R = nuke.toNode(_constant_R) _sheetNode_L = nuke.toNode(_contactSheet_L) _sheetNode_R = nuke.toNode(_contactSheet_R) _conNode_L = nuke.toNode(_constant_L) _conNode_R = nuke.toNode(_constant_R) if len(_sortedCamL) <= 3: for _x in range(3): _sheetNode_L.setInput(_x, _conNode_L) if len(_sortedCamR) <= 3: for _x in range(3): _sheetNode_R.setInput(_x, _conNode_R) for _k, _v in _sortedCamL.iteritems(): _sourceNode = _v #查找摄像机相对应的方格通道,链接,并调整位置 if _k[0] == "_": myKey = _k[1::] else: myKey = _k if len(_sortedCamL) <= 3: _sheetNode_L.setInput(self.num[myKey] - 1, _sourceNode) _pick = _patternL[self.num[myKey] - 1] _sourceNode.setXYpos(_bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) #取消所有的选择 nuke.delete(_conNode_L) self.setSelecteNone() for _k, _v in _sortedCamL.iteritems(): _v.setSelected(1) _sheetNode_L.setXYpos(_dot.xpos() + _bbox[0] * 0, _dot.ypos() + _bbox[1] * 1) #_conNode.setXYpos(_dot.xpos()+_bbox[0]*1+86,_dot.ypos()+_bbox[1]*1-45) bd_L = nukescripts.autoBackdrop() bd_L.knob('label').setValue(_backDropStr_L) myOldbdHeight = bd_L.knob('bdheight').value() bd_L.knob('bdheight').setValue(myOldbdHeight + 15) for _k, _v in _sortedCamR.iteritems(): _sourceNode = _v #查找摄像机相对应的方格通道,链接,并调整位置 if _k[0] == "_": myKey = _k[1::] else: myKey = _k if len(_sortedCamR) <= 3: _sheetNode_R.setInput(self.num[myKey] - 1, _sourceNode) _pick = _patternR[self.num[myKey] - 1] _sourceNode.setXYpos(_bbox[0] * _pick[0] + _dot.xpos() + 50, _bbox[1] * _pick[1] + _dot.ypos()) #取消所有的选择 nuke.delete(_conNode_R) self.setSelecteNone() for _k, _v in _sortedCamR.iteritems(): _v.setSelected(1) _sheetNode_R.setXYpos(_dot.xpos() + _bbox[0] * 3 + 50, _dot.ypos() + _bbox[1] * 1) nuke.delete(_dot) bd_R = nukescripts.autoBackdrop() bd_R.knob('label').setValue(_backDropStr_L) myOldbdHeight = bd_R.knob('bdheight').value() bd_R.knob('bdheight').setValue(myOldbdHeight + 15) self.setSelecteNone() nukescripts.stereo.setViewsForStereo() joinviewsNode = nuke.createNode('JoinViews', inpanel=False) _sheetNode_R.setSelected(1) _sheetNode_L.setSelected(1) joinviewsNode.setInput(1, _sheetNode_R) joinviewsNode.setInput(0, _sheetNode_L) joinviewsNode.setXYpos((_sheetNode_L.xpos() + _sheetNode_R.xpos()) / 2, _sheetNode_R.ypos() + 80)
def mergeCamera(self, flag, mymodel): self.mode = mymodel #选择所有的节点 _source = nuke.selectedNodes('Read') self.numSelect = len(_source) #定义_contactSheet方格 _constant黑板 _backDropStr背板、保存的摄像机字典 _contactSheet, _constant, _backDropStr = '', '', '' _sortedCam = {} #搜索所选的内容 if len(nuke.selectedNodes('ContactSheet')): _contactSheet = nuke.selectedNodes('ContactSheet')[0] if len(nuke.selectedNodes('Constant')): _constant = nuke.selectedNodes('Constant')[0] if len(_source) == 0: nuke.message('No Read Nodes Selected...') return if len(_source) != flag: nuke.message( '\xe4\xbd\xa0\xe6\x89\x80\xe9\x80\x89\xe6\x8b\xa9\xe7\x9a\x84\xe7\xb4\xa0\xe6\x9d\x90\xe4\xb8\xaa\xe6\x95\xb0\xe4\xb8\x8e\xe4\xbd\xa0\xe9\x80\x89\xe6\x8b\xa9\xe7\x9a\x84\xe5\x90\x88\xe5\xb9\xb6\xe9\x80\x89\xe9\xa1\xb9\xe4\xb8\x8d\xe7\x9b\xb8\xe5\x90\x8c' ) return #以所选的第一个素材为例,定义素材的格式_w _h _node = _source[0] #获取第一个素材在nuke中的位置 _w = _node.knob('format').value().width() _h = _node.knob('format').value().height() #获取第一个素材的大小 _bbox = [_node.screenWidth(), _node.screenHeight()] _pos = [_node.xpos(), _node.ypos()] #常见点节点,并设置它的坐标为第一个素材的节点位置 _dot = nuke.nodes.Dot() _dot.setXYpos(_pos[0], _pos[1]) _pattern = '' if self.numSelect <= 3: _pattern = ((-1, 0), (0, 0), (1, 0)) elif self.numSelect == 6: _pattern=((-2,-2),(-1,-2),(0,-2),(1,-2),\ (-2,-1),(-1,-1),(0,-1),(1,-1),\ (-2,0),(-1,0),(0,0),(1,0)) #当方格为空时,并设置它的坐标为第一个素材的节点位置 if _contactSheet == "": if self.numSelect <= 3: _contactSheet = nuke.nodes.ContactSheet( width=_w * 3, height=_h * 1, rows=1, columns=3, roworder='TopButtom').name() elif self.numSelect == 6: _contactSheet = nuke.nodes.ContactSheet( width=_w * 4, height=_h * 3, rows=3, columns=4, roworder='TopButtom').name() _node = nuke.toNode(_contactSheet) _node = _node.setXYpos(_dot.xpos() + _bbox[0] * 0, _dot.ypos() + _bbox[1] * 2) #在所有的尺寸格式中,寻找跟素材一样样式,在创建黑板,并设置位置 if _constant == "": _allFormat = nuke.formats() for _eachFormat in _allFormat: if _eachFormat.width() == _w and _eachFormat.height() == _h: _constant = nuke.nodes.Constant( format=_eachFormat.name()).name() _node = nuke.toNode(_constant) #在每个素材中记录摄像机,并记录黑板的名字 for each in _source: camStr = self.checkFile(each) if camStr: _sortedCam[camStr[0]] = each if not _backDropStr: _backDropStr = camStr[1] else: each.setSelected(False) _sheeNode = nuke.toNode(_contactSheet) _conNode = nuke.toNode(_constant) #根据所选的素材的个数创建ContactSheet和Constant连接的线 if self.numSelect == 3: for _x in range(9): _sheeNode.setInput(_x, _conNode) else: for _x in range(18): _sheeNode.setInput(_x, _conNode) #判断素材的格式 myfileFlagEXR = False #查询第一个素材的路径 myfileName = _source[0]['file'].value() #获取素材的格式 myfileNameType = os.path.splitext(myfileName)[1] if myfileNameType: if myfileNameType.find('exr') >= 0: myfileFlagEXR = True myii = 0 for _k, _v in _sortedCam.iteritems(): _sourceNode = _v #查找摄像机对应的方格通道,链接,并调整位置 if _k[0] == "_": myKey = _k[1::] else: myKey = _k #当时exr时,添加shuffle通道节点 if self.mode == 1: if self.numSelect == 3: _sheeNode.setInput(self.num[myKey] - 1, _sourceNode) _pick = _pattern[self.num[myKey] - 1] #设置素材的在nuke中的位置 _sourceNode.setXYpos(_bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) elif self.numSelect == 6: _sheeNode.setInput(self.num6[myKey] - 1, _sourceNode) _pick = _pattern[self.num6[myKey] - 1] _sourceNode.setXYpos(_bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) #当时exr时,根据需要添加shuffle通道节点 elif self.mode == 2: if self.numSelect == 3: _pick = _pattern[self.num[myKey] - 1] _sourceNode.setXYpos(_bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) if not myfileFlagEXR: _sheeNode.setInput(self.num[myKey] - 1, _sourceNode) _sourceNode.setSelected(1) else: if myii == 0: myShuffle = nuke.nodes.Shuffle() myShuffle.setInput(0, _sourceNode) _sheeNode.setInput(self.num[myKey] - 1, myShuffle) myShuffle.setXYpos( _bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) else: self.setSelecteNone() newMyShuffle = nuke.clone(myShuffle) newMyShuffle.setInput(0, _sourceNode) _sheeNode.setInput(self.num[myKey] - 1, newMyShuffle) newMyShuffle.setXYpos( _bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) elif self.numSelect == 6: _pick = _pattern[self.num6[myKey] - 1] _sourceNode.setXYpos(_bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) if not myfileFlagEXR: _sheeNode.setInput(self.num6[myKey] - 1, _sourceNode) _sourceNode.setSelected(1) else: if myii == 0: myShuffle = nuke.nodes.Shuffle() myShuffle.setInput(0, _sourceNode) _sheeNode.setInput(self.num6[myKey] - 1, myShuffle) myShuffle.setXYpos( _bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) else: self.setSelecteNone() newMyShuffle = nuke.clone(myShuffle) newMyShuffle.setInput(0, _sourceNode) _sheeNode.setInput(self.num6[myKey] - 1, newMyShuffle) newMyShuffle.setXYpos( _bbox[0] * _pick[0] + _dot.xpos(), _bbox[1] * _pick[1] + _dot.ypos()) myii = myii + 1 _sheeNode.setSelected(1) for each in _source: each.setSelected(1) if self.numSelect == 3: _sheeNode.setXYpos(_dot.xpos() + _bbox[0] * 0, _dot.ypos() + _bbox[1] * 2 - 30) _conNode.setXYpos(_dot.xpos() + _bbox[0] * 1, _dot.ypos() + _bbox[1] * 1 - 10) elif self.numSelect == 6: _sheeNode.setXYpos(_dot.xpos() + _bbox[0] * 0 - 45, _dot.ypos() + _bbox[1] * 1) _conNode.setXYpos(_dot.xpos() + 10, _dot.ypos() + 10) #if self.numSelect==3: #_conNode.setXYpos(_dot.xpos()+_bbox[0]*1,_dot.ypos()+_bbox[1]*1-10) #删除黑板 conUsed = _conNode.dependent() if not conUsed: nuke.delete(_conNode) else: _conNode.setSelected(1) nuke.delete(_dot) bd = nukescripts.autoBackdrop() bd.knob('label').setValue(_backDropStr) myOldbdHeight = bd.knob('bdheight').value() bd.knob('bdheight').setValue(myOldbdHeight + 15)