Python nuke.selectedNodes() Examples
The following are 18
code examples of nuke.selectedNodes().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
nuke
, or try the search function
.
Example #1
Source File: cryptomatte_utilities.py From NukeToolSet with MIT License | 6 votes |
def decryptomatte_nodes(nodes, ask): gizmos = [] for node in nodes: if node.Class() == "Cryptomatte": gizmos.append(node) if not gizmos: return if not ask or nuke.ask(('Replace %s Cryptomatte gizmos with expression nodes? ' 'Replaced Gizmos will be disabled and selected.') % (len(gizmos))): for gizmo in gizmos: _decryptomatte(gizmo) for node in nuke.selectedNodes(): node.knob("selected").setValue(False) for gizmo in gizmos: gizmo.knob("selected").setValue(True) ############################################# # Decryptomatte helpers #############################################
Example #2
Source File: cryptomatte_utilities.py From Cryptomatte with BSD 3-Clause "New" or "Revised" License | 6 votes |
def decryptomatte_nodes(nodes, ask): """ Replaces Cryptomatte gizmos with equivelant nodes. """ gizmos = [n for n in nodes if n.Class() == "Cryptomatte"] if not gizmos: return if not ask or nuke.ask(('Replace %s Cryptomatte gizmos with expression nodes? ' 'Replaced Gizmos will be disabled and selected.') % len(gizmos)): for gizmo in gizmos: _decryptomatte(gizmo) for node in nuke.selectedNodes(): node.knob("selected").setValue(False) for gizmo in gizmos: gizmo.knob("selected").setValue(True) ############################################# # Decryptomatte helpers #############################################
Example #3
Source File: __init__.py From anima with MIT License | 6 votes |
def create_auto_crop_writer(): """creates a write node for every selected node, and sets the autocrop flag to auto crop the output for fast reading """ # get selected nodes and deselect them nodes = nuke.selectedNodes() [node.setSelected(False) for node in nodes] write_nodes = [] for node in nodes: write_node = nuke.createNode('Write') file_path = node['file'].value() filename_with_number_seq, ext = os.path.splitext(file_path) filename, number_seq = os.path.splitext(filename_with_number_seq) write_node['file'].setValue( filename + '_auto_cropped' + number_seq + ext ) write_node['channels'].setValue('all') write_node['autocrop'].setValue(True) write_node.setXpos(node.xpos() + 100) write_node.setYpos(node.ypos()) # connect it to the original node write_node.setInput(0, node) write_node.setSelected(False) # store the write node write_nodes.append(write_node) # connect the write nodes to afanasy if afanasy exists try: afanasy = nuke.createNode('afanasy') for i, node in enumerate(write_nodes): afanasy.setInput(i, node) except RuntimeError: pass
Example #4
Source File: setLocallisation.py From NukeToolSet with MIT License | 6 votes |
def selectNodes(self): selectNodes = nuke.selectedNodes() if selectNodes: self.upLocalizationPolicy(selectNodes) else: nuke.message("请选择节点")
Example #5
Source File: lib.py From core with MIT License | 6 votes |
def maintained_selection(): """Maintain selection during context Example: >>> with maintained_selection(): ... node['selected'].setValue(True) >>> print(node['selected'].value()) False """ previous_selection = nuke.selectedNodes() try: yield finally: # unselect all selection in case there is some current_seletion = nuke.selectedNodes() [n['selected'].setValue(False) for n in current_seletion] # and select all previously selected nodes if previous_selection: [n['selected'].setValue(True) for n in previous_selection]
Example #6
Source File: extract_group.py From pyblish-bumpybox with GNU Lesser General Public License v3.0 | 5 votes |
def process(self, instance): import os import nuke if not instance.data["publish"]: return file_path = instance.data["output_path"] directory = os.path.dirname(file_path) # Create workspace if necessary if not os.path.exists(directory): os.makedirs(directory) # Export gizmo # Deselect all nodes for node in nuke.selectedNodes(): node["selected"].setValue(False) instance[0]["selected"].setValue(True) nuke.nodeCopy(file_path) data = "" with open(file_path, "r") as f: data = f.read() data = data.replace("set cut_paste_input [stack 0]\n", "") data = data.replace("push $cut_paste_input\n", "") data = data.replace("Group {\n", "Gizmo {\n") with open(file_path, "w") as f: f.write(data)
Example #7
Source File: collect_selection.py From pyblish-bumpybox with GNU Lesser General Public License v3.0 | 5 votes |
def process(self, context): import nuke context.data["selection"] = nuke.selectedNodes()
Example #8
Source File: extract_nuke.py From pyblish-bumpybox with GNU Lesser General Public License v3.0 | 5 votes |
def duplicate_node(self, node, to_file=None): """Slightly convoluted but reliable(?) way duplicate a node, using the same functionality as the regular copy and paste. Could almost be done tidily by doing: for knobname in src_node.knobs(): value = src_node[knobname].toScript() new_node[knobname].fromScript(value) ..but this lacks some subtly like handling custom knobs to_file can be set to a string, and the node will be written to a file instead of duplicated in the tree """ import nuke # Store selection orig_selection = nuke.selectedNodes() # Select only the target node [n["selected"].setValue(False) for n in nuke.selectedNodes()] node["selected"].setValue(True) # If writing to a file, do that, restore the selection and return if to_file is not None: nuke.nodeCopy(to_file) [n["selected"].setValue(False) for n in orig_selection] return # Copy the selected node and clear selection again nuke.nodeCopy("%clipboard%") node["selected"].setValue(False) if to_file is None: # If not writing to a file, call paste function, and the new node # becomes the selected nuke.nodePaste("%clipboard%") new_node = nuke.selectedNode() # Restore original selection [n["selected"].setValue(False) for n in nuke.selectedNodes()] [n["selected"].setValue(True) for n in orig_selection] return new_node
Example #9
Source File: cryptomatte_utilities.py From NukeToolSet with MIT License | 5 votes |
def decryptomatte_selected(ask=False): decryptomatte_nodes(nuke.selectedNodes(), ask)
Example #10
Source File: pipeline.py From core with MIT License | 5 votes |
def process(self): from nukescripts import autoBackdrop instance = None if (self.options or {}).get("useSelection"): nodes = nuke.selectedNodes() if not nodes: nuke.message("Please select nodes that you " "wish to add to a container") return elif len(nodes) == 1: # only one node is selected instance = nodes[0] if not instance: # Not using selection or multiple nodes selected bckd_node = autoBackdrop() bckd_node["tile_color"].setValue(int(self.node_color, 16)) bckd_node["note_font_size"].setValue(24) bckd_node["label"].setValue("[{}]".format(self.name)) instance = bckd_node # add avalon knobs lib.set_avalon_knob_data(instance, self.data) lib.add_publish_knob(instance) return instance
Example #11
Source File: extract_review.py From pyblish-bumpybox with GNU Lesser General Public License v3.0 | 5 votes |
def duplicate_node(self, node, to_file=None): """Slightly convoluted but reliable(?) way duplicate a node, using the same functionality as the regular copy and paste. Could almost be done tidily by doing: for knobname in src_node.knobs(): value = src_node[knobname].toScript() new_node[knobname].fromScript(value) ..but this lacks some subtly like handling custom knobs to_file can be set to a string, and the node will be written to a file instead of duplicated in the tree """ import nuke # Store selection orig_selection = nuke.selectedNodes() # Select only the target node [n["selected"].setValue(False) for n in nuke.selectedNodes()] node["selected"].setValue(True) # If writing to a file, do that, restore the selection and return if to_file is not None: nuke.nodeCopy(to_file) [n["selected"].setValue(False) for n in orig_selection] return # Copy the selected node and clear selection again nuke.nodeCopy("%clipboard%") node["selected"].setValue(False) if to_file is None: # If not writing to a file, call paste function, and the new node # becomes the selected nuke.nodePaste("%clipboard%") new_node = nuke.selectedNode() # Restore original selection [n["selected"].setValue(False) for n in nuke.selectedNodes()] [n["selected"].setValue(True) for n in orig_selection] return new_node
Example #12
Source File: toggle_input.py From NukeToolSet with MIT License | 5 votes |
def toggleInput(): sel = nuke.selectedNodes() if len(sel): toggleVal = not bool(sel[0].knob('hide_input').getValue()) for node in sel: if node.knob('hide_input') != None: node.knob('hide_input').setValue(toggleVal) else: nodes = nuke.allNodes() toggleVal = not bool(nodes[0].knob('hide_input').getValue()) for node in nodes: if node.knob('hide_input') != None: node.knob('hide_input').setValue(toggleVal)
Example #13
Source File: ListShuffle.py From NukeToolSet with MIT License | 5 votes |
def shuffle(): for selected_node in nuke.selectedNodes(): if selected_node.Class() == 'Read': all_channels = selected_node.channels() all_channels = list(set([i.split('.')[0] for i in all_channels])) for channel in all_channels: shuffle_node = nuke.createNode('Shuffle', inpanel=False) shuffle_node['name'].setValue(channel+'_'+selected_node['name'].getValue()) shuffle_node['in'].setValue(channel) shuffle_node.setInput(0, selected_node) shuffle_node['postage_stamp'].setValue(1)
Example #14
Source File: relativeFilePath.py From NukeToolSet with MIT License | 5 votes |
def doIt(self): nodesToProcess = nuke.selectedNodes() if self.nodeSelectionChoice.currentIndex() == 1 else nuke.allNodes() processFunction = makeNodesAbsolute if self.commandTypeChoice.currentIndex() == 1 else makeNodesRelative filteredNodes = self.filterByNodeType(nodesToProcess) choosenKnobTypes = self.collectChoosenTypes(self.supportedKnobTypes) result = processFunction(filteredNodes,choosenKnobTypes) self.warningsText.setText("\n\n".join(result['warnings'])) self.resultsText.setText("\n".join(result['replacements']))
Example #15
Source File: __init__.py From anima with MIT License | 5 votes |
def open_selected_nodes_in_file_browser(): """opens selected node in filebrowser """ nodes = nuke.selectedNodes() for node in nodes: open_node_in_file_browser(node)
Example #16
Source File: lib.py From core with MIT License | 5 votes |
def reset_selection(): """Deselect all selected nodes """ for node in nuke.selectedNodes(): node["selected"] = False
Example #17
Source File: cryptomatte_utilities.py From Cryptomatte with BSD 3-Clause "New" or "Revised" License | 5 votes |
def decryptomatte_selected(ask=False): decryptomatte_nodes(nuke.selectedNodes(), ask)
Example #18
Source File: extract_backdrop.py From pyblish-bumpybox with GNU Lesser General Public License v3.0 | 4 votes |
def process(self, instance): import os import nuke if not instance.data["publish"]: return file_path = instance.data["output_path"] directory = os.path.dirname(file_path) # Create workspace if necessary if not os.path.exists(directory): os.makedirs(directory) # Store selection selected_nodes = nuke.selectedNodes() # Export gizmo # Deselect all nodes for node in nuke.selectedNodes(): node["selected"].setValue(False) instance[0]["selected"].setValue(True) for node in instance[0].getNodes(): node["selected"].setValue(True) nuke.nodeCopy(file_path) # Restore selection for node in nuke.selectedNodes(): node["selected"].setValue(False) for node in selected_nodes: node["selected"].setValue(True) # Export backdrop data = "" with open(file_path, "r") as f: data = f.read() data = data.replace("set cut_paste_input [stack 0]\n", "") data = data.replace("push $cut_paste_input\n", "") with open(file_path, "w") as f: f.write(data)