Example #1
0
def copyMasterNodeStyle():
	'''Copy Master node style to children that are expression linked'''

	n = nuke.selectedNode()

	for d in nuke.dependentNodes(nodes=[n]):
		d['tile_color'].setValue(n['tile_color'].value())
		d['note_font_color'].setValue(n['note_font_color'].value())
Example #2
0
def clear_the_outgoing_link():
    nodes = nuke.selectedNodes()
    for i in nodes:
        ndeps = nuke.dependentNodes(nuke.EXPRESSIONS, i)
        for knob_name in ndeps:
            knob_name.knob('disable').clearAnimated()
        if i.Class() == "Constant":
            nuke.delete(i)
Example #3
0
def _useAsInputProcess():
  n = nuke.selectedNode()
  [i['selected'].setValue(False) for i in nuke.allNodes()]
  # FIXME: these two calls should have the arguments in the same order, or even better change the node bindings so they can go.
  if nuke.dependencies([n], nuke.INPUTS | nuke.HIDDEN_INPUTS) or nuke.dependentNodes(nuke.INPUTS | nuke.HIDDEN_INPUTS, [n]):
    m = nuke.createNode(n.Class())
  else:
    m = n
  if m is not n: _copyKnobsFromScriptToScript(n, m)
  viewer = nuke.activeViewer().node()
  viewer['input_process'].setValue(True)
  viewer['input_process_node'].setValue(m.name())
Example #4
0
def node_delete(popupOnError=False):
    d = nuke.dependentNodes(nuke.EXPRESSIONS | nuke.HIDDEN_INPUTS,
                            nuke.selectedNodes(), False)
    l = ""
    for i in d:
        if i.Class() != "Viewer":
            l = l + i.fullName() + ", "
    l = l[0:len(l) - 2]
    if len(l) > 0:
        if not nuke.ask(
                "The nodes you are deleting are used by expressions in:\n" +
                l + "\nAre you sure you want to delete?"):
            return
    nuke.nodeDelete(popupOnError)
Example #5
0
def connected(nodes, upstream=True, downstream=True):
    # return all upstream and/or downstream nodes of node
    # based on nuke.overrides.selectConnectedNodes()
    all_deps = set()
    deps_list = nodes
    evaluate_all = True
    while deps_list:
        deps = []
        if upstream:
            deps += nuke.dependencies(deps_list, connection_filter)
        if downstream:
            deps += nuke.dependentNodes(connection_filter, deps_list, evaluate_all)
        evaluate_all = False
        deps_list = [d for d in deps if d not in all_deps and not all_deps.add(d)]
    return all_deps
Example #6
0
def copySpecial():
    """copy selection, paste and reconnect (just one node)"""
    depNode = nuke.dependencies(nuke.selectedNode())
    dependNode = nuke.dependentNodes(nuke.INPUTS or nuke.HIDDEN_INPUTS or nuke.EXPRESSIONS, [nuke.selectedNode()])
    i = 0
    if dependNode[0].Class() in ['Scene', 'MergeGeo']:
        i = nuke.inputs(dependNode[0])+1

    nuke.nodeCopy(nukescripts.cut_paste_file())

    for node in nuke.allNodes():
        node['selected'].setValue(0)

    nuke.nodePaste(nukescripts.cut_paste_file())

    newNode = nuke.selectedNode()
    newNode.setInput(0, depNode[0])
    dependNode[0].setInput(i+1, newNode)
Example #7
0
    def getConnectedNodes(self, node):
        '''
        Returns a two-tuple of lists. Each list is made up of two-tuples in the
        form ``(index, nodeObj)`` where 'index' is an input index and 'nodeObj'
        is a Nuke node.

        The first list contains the inputs to 'node', where each 'index' is the
        input index of 'node' itself.

        The second contains its outputs, where each 'index' is the input index that
        is connected to 'node'.
        '''
        inputNodes = [(i, node.input(i)) for i in range(node.inputs())]
        outputNodes = []
        for depNode in nuke.dependentNodes(nuke.INPUTS | nuke.HIDDEN_INPUTS, node):
            for i in range(depNode.inputs()):
                if depNode.input(i) == node:
                    outputNodes.append((i, depNode))
        return (inputNodes, outputNodes)
Example #8
0
def precomp_selected():

  nodes = nuke.selectedNodes()
  if len(nodes) == 0:
    g = nuke.createNode( "Precomp" )
    return

  options = PrecompOptions()

  if not options.askUserForOptions():
    return False

  sel = nodes[0]

  ## select upstream nodes
  if len( nodes ) == 1:
    upstreamNodes = nuke.dependencies( nodes )
    while len ( upstreamNodes ) != 0:
      nodes += upstreamNodes
      upstreamNodes = nuke.dependencies( upstreamNodes )

  left = right = nodes[0].xpos()
  top = bottom = nodes[0].ypos()

  nodeSize = 100
  titleHeight = 50

  inputs = []

  for n in nodes:
    n["selected"].setValue ( True )
    if n.xpos() < left:
      left = n.xpos()

    if n.xpos() > right:
      right = n.xpos()

    if n.ypos() < top:
      top = n.ypos()

    if n.ypos() > bottom:
      bottom = n.ypos()

    for i in range( 0, n.inputs() ):
      if not n.input(i):
        continue

      if not n.input(i) in nodes:
        inputs.append( n.input(i) )

  ## find all the dependent nodes
  inputDeps = []
  expressionDeps = []

  for n in nodes:
    for d in nuke.dependentNodes( nuke.INPUTS, [n]):
      if d not in nodes:
        if d.Class() != 'Viewer':
          inputIndices = [i for i in range(d.inputs()) if d.input(i) == n]
          inputDeps.append( (d, inputIndices) )

    for d in nuke.dependencies( [n], nuke.EXPRESSIONS ):
      if d not in nodes:
        expressionDeps.append( d )

  if len(inputDeps) > 1:
    nuke.message( "You cannot precomp the selected nodes because there are multiple outputs." )
    return

  addLinkedExpressionNodes = False
  if len(expressionDeps) > 0:
    addLinkedExpressionNodes = nuke.ask( "Warning: The selected nodes have expressions to nodes outside the precomp. Do you want to copy these nodes to the precomp?" )

  ## make group and export
  if len( nodes ) == 1 and nodes[0].Class() == "Group":
    group = nodes[0]
  else:
    group = nuke.makeGroup( False )

  with group:
    outputInputs = []
    output = group.output()
    for i in range(0, output.inputs()):
      outputInputs.append( output.input(i) )

    ## insert write node or use existing one
    outInp = output.input(0)
    if outInp is None or outInp.Class() != "Write":
      w = nuke.createNode( "Write", inpanel = False)
      w.setInput( 0, None )
    else:
      w = outInp

    for i in range(0, len(outputInputs) ):
      w.setInput( i, outputInputs[i] )
      output.setInput(i, None )

    output.setInput(0, w )

    w.knob("file").setValue( options.renderPath )
    type = os.path.splitext( options.renderPath)[1][1:].lower()
    w.knob("file_type").setValue( type )
    w.knob("channels").setValue( options.channels )

    for n in nuke.allNodes():
      n['selected'].setValue( False )

  if addLinkedExpressionNodes:
    for n in nuke.allNodes():
      n['selected'].setValue( False )

    for n in expressionDeps:
      n['selected'].setValue( True )

    nuke.nodeCopy ( '%clipboard%' )

    with group:
      nuke.nodePaste( '%clipboard%' )

  writeOk = True
  with group:
    try:
      nuke.tcl("export_as_precomp",  options.scriptPath)
    except:
      nuke.message( "Could not write precomp script, permission denied, please specify a different \'script path\' and try again.")
      writeOk = False

    for n in nuke.selectedNodes():
      n['selected'].setValue( False )

  if group != nodes[0]:
    group['selected'].setValue( False )
    nuke.delete( group )

  if not writeOk:
    for n in nuke.selectedNodes():
      n['selected'].setValue( False )

    for n in nodes:
      n['selected'].setValue( True )

    return

  ## reload saved out script
  g = nuke.createNode( "Precomp" )
  g[ "file" ].setValue( options.scriptPath )

  #nuke.tprint( "Selected Node: " + sel.name() )

  for d in inputDeps:
    node = d[0]
    for inp in d[1]:
      #nuke.tprint ( "Reconnecting dep " + node.name() + " input " + str(inp) )
      node.setInput(inp, g)

  ## reconnect inputs, if any
  for i in range(0, len(inputs)):
    #nuke.tprint ( "Reconnecting input " + inputs[i].name() + " " + str(i) )
    g.setInput(i, inputs[i] )

  pad = 5

  if options.addBackdrop:
    b = nuke.createNode( "BackdropNode", inpanel = False )
    width = int(math.fabs(right - left)) + (pad * 2) + nodeSize
    height = int(math.fabs(bottom - top)) + ( pad * 2 ) + nodeSize + titleHeight
    b['label'].setValue( os.path.basename( options.scriptPath ) )
    b['note_font_size'].setValue( 18 )
    b.setXYpos( left - pad * 2, top - ( pad * 2) - titleHeight )
    b.knob( "bdwidth" ).setValue( width  )
    b.knob( "bdheight").setValue( height )
    b.knob( "z_order" ).setValue( 0 )
    b['selected'].setValue(False)
    g.setXYpos( b.xpos() + width/2 - nodeSize/2, b.ypos() + height + pad * 2 )
  elif options.delete:
    for n in nodes:
      nuke.delete( n )

  if len(inputs) > 0:
    nuke.message( "Warning: The precomp script requires inputs and may not render the same independent of its parent script." )

  return group