def main(): target_node = nuke.selectedNode() if target_node.Class() != "Read": pass # get target node's position value pos_x, pos_y = target_node.xpos(), target_node.ypos() # get target node's channels and layers channels = target_node.channels() nukeLayers = nuke.layers() nukeLayers.remove("rgb") nukeLayers.remove("rgba") nukeLayers.remove("alpha") layerNames = [] for i in channels: t = i.split(".") t.pop(1) layerNames.extend(t) passes = [] for layer in nukeLayers: if layer in layerNames: passes.append(layer) main_dot = nuke.Node("Dot") main_dot_y = main_dot.ypos() if main_dot_y != pos_y + 150: main_dot.setYpos(int(pos_y + 150)) main_dot.setInput(0, target_node) main_dot_y = main_dot["ypos"].getValue() main_dot_x = main_dot["xpos"].getValue() multi = 0 for layer in passes: pos_offset = 150 * multi dot_node = nuke.Node("Dot") dot_node['name'].setValue("%s_dot" % layer) dot_node.setInput(0, main_dot) dot_node.setXYpos(int(main_dot_x + pos_offset), int(main_dot_y)) dot_node_y = dot_node.ypos() multi = multi + 1 shuffle_node = nuke.Node("Shuffle") shuffle_node['name'].setValue(layer) shuffle_node.setInput(0, dot_node) shuffle_node["in"].setValue(layer) shuffle_node.setYpos(dot_node_y + 150) nuke.message("Done!") return
def load(self, context, name=None, namespace=None, options=None): representation = context["representation"] nodes = list() for name, data in representation["data"]["sequence"].items(): read = nuke.Node("Read") nodes.append(read) self.set_path(read, aov_name=name, file_name=data["fname"]) self.set_format(read, data["resolution"]) self.set_range(read, start=data["seqStart"], end=data["seqEnd"]) # Mark aov name lib.set_avalon_knob_data(read, {("aov", "AOV"): name}) asset = context["asset"] asset_name = asset["data"].get("shortName", asset["name"]) families = context["subset"]["data"]["families"] family_name = families[0].split(".")[-1] namespace = namespace or "%s_%s" % (asset_name, family_name) pipeline.containerise(name=context["subset"]["name"], namespace=namespace, nodes=nodes, context=context, loader=self.__class__.__name__, no_backdrop=True)
def load(self, context, name=None, namespace=None, options=None): representation = context["representation"] precomp = nuke.Node("Precomp") self.setup_precomp(precomp, representation) nodes = [precomp] asset = context["asset"] asset_name = asset["data"].get("shortName", asset["name"]) families = context["subset"]["data"]["families"] family_name = families[0].split(".")[-1] namespace = namespace or "%s_%s" % (asset_name, family_name) pipeline.containerise(name=context["subset"]["name"], namespace=namespace, nodes=nodes, context=context, loader=self.__class__.__name__, no_backdrop=True)
def create_write_node(node, write_type, colorspace_override=None): output_keys = {'fromVFX': node['file_output'], 'matte': node['matte_output']} output_file = output_keys[write_type] if colorspace_override == None: colorspace_selection = {'fromVFX': node['read_colorspace'], 'matte': 'ACES - ACEScg'} colorspace = colorspace_selection[write_type] else: colorspace = colorspace_override write_node = nuke.Node('Write') write_node['file'].setValue(output_file) write_node["create_directories"].setValue(1) write_node["colorspace"].setValue(colorspace) write_node["postage_stamp"].setValue(1) write_node["use_limit"].setValue(1) write_node["first"].setValue(node['first_frame']) write_node["last"].setValue(node['last_frame']) return write_node
def build_sequences(cls, sequences, root_path, group_name, stamp_name, start, end): cls.resolve_path(sequences, root_path) # Filter out multi-channle sequence multiaovs = OrderedDict() singleaovs = OrderedDict() for aov_name in sorted(sequences, key=lambda k: k.lower()): data = sequences[aov_name] if cls.is_singleaov(data["_resolved"], start): singleaovs[aov_name] = data else: multiaovs[aov_name] = data multiaov_reads = list() singleaov_reads = OrderedDict() lib.reset_selection() for aov_name, data in multiaovs.items(): read = nuke.Node("Read") read["selected"].setValue(False) read.autoplace() path = data["_resolved"] cls.set_path(read, aov_name=aov_name, path=path) # cls.set_format(read, data["resolution"]) cls.set_range(read, start=start, end=end) # Mark aov name lib.set_avalon_knob_data(read, {("aov", "AOV"): aov_name}) multiaov_reads.append(read) nodes = multiaov_reads[:] if singleaovs: if "beauty" in singleaovs: # Default channel (RGBA) for exr_merge beauty_name = "beauty" else: # Ask artist if want to assign a beauty if not found beauty_name = cls.pick_beauty(singleaovs, group_name) with command.viewer_update_and_undo_stop(): group = nuke.createNode("Group") group.autoplace() with nuke_lib.group_scope(group): for aov_name, data in singleaovs.items(): read = nuke.Node("Read") read["selected"].setValue(False) read.autoplace() path = data["_resolved"] cls.set_path(read, aov_name=aov_name, path=path) # cls.set_format(read, data["resolution"]) cls.set_range(read, start=start, end=end) # Mark aov name knob = ("aov", "AOV") lib.set_avalon_knob_data(read, {knob: aov_name}) singleaov_reads[aov_name] = read if beauty_name: beauty = singleaov_reads.pop(beauty_name) else: beauty = singleaov_reads.popitem()[1] nuke_lib.exr_merge(beauty, singleaov_reads.values()) output = nuke.createNode("Output") output.autoplace() stamp = nuke.createNode("PostageStamp") stamp.setName(stamp_name) group.setName(group_name) nodes += [stamp, group] + group.nodes() return nodes
def CreateOnSelection(_kind): #If the viewer is connected to a node we will use input 0 for ref. Else we just use the viewer itself. if nuke.activeViewer().node().input(0): myNode = nuke.activeViewer().node().input(0) if not nuke.selectedNodes( ): #Trying to be smart by assuming that you don't want to add a node to nothing. myNode.setSelected(1) else: myNode = nuke.activeViewer().node() bboxinfo = nuke.activeViewer().node()['colour_sample_bbox'].value( ) #Get the position info from the colour sample bbox aspect = float(myNode.width() * myNode.pixelAspect()) / float( myNode.height() ) #Calcualte the aspect (thanks Tom van Dop for notifying and Jelmen Palsterman for the correction!) cornerA = [ (bboxinfo[0] * 0.5 + 0.5) * myNode.width(), (((bboxinfo[1] * 0.5) + (0.5 / aspect)) * aspect) * myNode.height() ] #Get the button left corner cornerB = [ (bboxinfo[2] * 0.5 + 0.5) * myNode.width(), (((bboxinfo[3] * 0.5) + (0.5 / aspect)) * aspect) * myNode.height() ] #Get the top right corner area_WH = [cornerB[0] - cornerA[0], cornerB[1] - cornerA[1]] #Get the width and height of the bbox area_Mid = [cornerA[0] + (area_WH[0] / 2), cornerA[1] + (area_WH[1] / 2)] #Get the center of the bbox if _kind == 'Crop': #-----Crop Node----- newNode = nuke.Node("Crop") newNode['box'].setValue( [cornerA[0], cornerA[1], cornerB[0], cornerB[1]]) elif _kind == 'ROI': #-----ROI----- nuke.activeViewer().node()["roi"].setValue(bboxinfo) elif _kind == 'Transform': #-----Tranform Node----- newNode = nuke.Node("Transform") newNode['center'].setValue([area_Mid[0], area_Mid[1]]) elif _kind == 'GridWarp': #-----GridWarp Node----- newNode = nuke.Node("GridWarp3") gridwarpLayout = gridWarpBaseStruct for x in range( 0, 5 ): #Remap placeholder values to x and y coordinates split up to 5 subdevisions gridwarpLayout = gridwarpLayout.replace( "_x%s" % x, "%.0f" % (cornerA[0] + ((area_WH[0] / 4) * x))) gridwarpLayout = gridwarpLayout.replace( "_y%s" % x, "%.0f" % (cornerA[1] + ((area_WH[1] / 4) * x))) gridwarpLayout = gridwarpLayout.replace( "_tx0", "%.3f" % (area_WH[0] / 12)) #Remap tangent's gridwarpLayout = gridwarpLayout.replace( "_ty0", "%.3f" % (area_WH[1] / 12)) #Remap tangent's newNode['source_grid_col'].fromScript(gridwarpLayout) #Set Source Grid newNode['destination_grid_col'].fromScript( gridwarpLayout) #Set Destination Grid if _kind == 'Text': newNode = nuke.Node("Text2") newNode['box'].setValue( [cornerA[0], cornerA[1], cornerB[0], cornerB[1]]) elif _kind == 'Radial': newNode = nuke.Node("Radial") newNode['area'].setValue( [cornerA[0], cornerA[1], cornerB[0], cornerB[1]]) elif _kind == 'Keylight': newNode = nuke.Node("OFXuk.co.thefoundry.keylight.keylight_v201") ColorR = myNode.sample(1, area_Mid[0], area_Mid[1], area_WH[0], area_WH[1]) ColorG = myNode.sample(2, area_Mid[0], area_Mid[1], area_WH[0], area_WH[1]) ColorB = myNode.sample(3, area_Mid[0], area_Mid[1], area_WH[0], area_WH[1]) newNode['screenColour'].setValue([ColorR, ColorG, ColorB]) elif _kind == 'Tracker': #If we allready have a tracker selexted then append tracks to exsisting tracker node. if myNode.Class() == "Tracker4": newNode = myNode nuke.show(newNode) else: #Creat a new tracker node newNode = nuke.Node("Tracker4") numColumns = 31 colTrackX = 2 colTrackY = 3 colRelTrack = 12 trackIdx = int(newNode["tracks"].toScript().split(" ")[3]) newNode['add_track'].execute() newNode.knob("tracks").setValue(area_Mid[0], numColumns * trackIdx + colTrackX) newNode.knob("tracks").setValue(area_Mid[1], numColumns * trackIdx + colTrackY) newNode.knob("tracks").setValue(-area_WH[0] / 2, numColumns * trackIdx + colRelTrack) newNode.knob("tracks").setValue( -area_WH[1] / 2, numColumns * trackIdx + colRelTrack + 1) newNode.knob("tracks").setValue( area_WH[0] / 2, numColumns * trackIdx + colRelTrack + 2) newNode.knob("tracks").setValue( area_WH[1] / 2, numColumns * trackIdx + colRelTrack + 3) elif _kind == 'CornerpinFrom': newNode = nuke.Node("CornerPin2D") newNode['from1'].setValue([cornerA[0], cornerA[1]]) newNode['from2'].setValue([cornerB[0], cornerA[1]]) newNode['from3'].setValue([cornerB[0], cornerB[1]]) newNode['from4'].setValue([cornerA[0], cornerB[1]]) elif _kind == 'CornerpinTo': newNode = nuke.Node("CornerPin2D") newNode['to1'].setValue([cornerA[0], cornerA[1]]) newNode['to2'].setValue([cornerB[0], cornerA[1]]) newNode['to3'].setValue([cornerB[0], cornerB[1]]) newNode['to4'].setValue([cornerA[0], cornerB[1]]) elif _kind == 'CornerpinFromTo': newNode = nuke.Node("CornerPin2D") newNode['to1'].setValue([cornerA[0], cornerA[1]]) newNode['to2'].setValue([cornerB[0], cornerA[1]]) newNode['to3'].setValue([cornerB[0], cornerB[1]]) newNode['to4'].setValue([cornerA[0], cornerB[1]]) newNode['from1'].setValue([cornerA[0], cornerA[1]]) newNode['from2'].setValue([cornerB[0], cornerA[1]]) newNode['from3'].setValue([cornerB[0], cornerB[1]]) newNode['from4'].setValue([cornerA[0], cornerB[1]]) elif _kind == 'Constant': newNode = nuke.Node("Constant", inpanel=False) ColorR = myNode.sample(1, area_Mid[0], area_Mid[1], area_WH[0], area_WH[1]) ColorG = myNode.sample(2, area_Mid[0], area_Mid[1], area_WH[0], area_WH[1]) ColorB = myNode.sample(3, area_Mid[0], area_Mid[1], area_WH[0], area_WH[1]) newNode['color'].setValue([ColorR, ColorG, ColorB, 1])