Package nuke :: Module overrides
[hide private]
[frames] | no frames]

Source Code for Module nuke.overrides

  1  # Copyright (c) 2009 The Foundry Visionmongers Ltd.  All Rights Reserved. 
  2   
  3  import sys, types, _nuke, os, re 
  4   
  5   
6 -def pluginAddPath(args, addToSysPath = True):
7 """ Adds all the paths to the beginning of the Nuke plugin path. 8 If the path already exists in the list of plugin paths, it is moved 9 to the start. If this command is executed inside an init.py then 10 the init.py in the path will be executed. 11 It also adds the paths to the sys.path, if addToSysPath is True.""" 12 if type(args) != types.TupleType and type(args) != types.ListType: 13 args = [args] 14 15 # Trim any trailing slashes or backslashes from the path, because they confuse python 16 args = [re.sub(r"[/\\]+$", "", arg) for arg in args] 17 # Remove any empty strings from the list 18 args = [arg for arg in args if arg] 19 20 # Nuke does it's own resolution of relative filenames, so that they end up 21 # relative to the right location. Rather than duplicating that logic here, 22 # we just get the difference between the pluginPath before and after we've 23 # added the new paths. 24 25 if addToSysPath: 26 oldPluginPath = tuple(_nuke.pluginPath()) 27 28 for i in args: 29 _nuke.pluginAddPath(i) 30 31 if addToSysPath: 32 newPaths = [ p for p in _nuke.pluginPath() if p not in oldPluginPath ] 33 for path in newPaths: 34 if path not in sys.path: 35 sys.path.insert(0, path)
36 37
38 -def pluginAppendPath(args, addToSysPath = True):
39 """ Add a filepath to the end of the Nuke plugin path. If the path 40 already exists in the list of plugin paths, it will remain at its 41 current position. 42 It also appends the paths to the sys.path, if addToSysPath is True.""" 43 if type(args) != types.TupleType and type(args) != types.ListType: 44 args = [args] 45 46 # Nuke does it's own resolution of relative filenames, so that they end up 47 # relative to the right location. Rather than duplicating that logic here, 48 # we just get the difference between the pluginPath before and after we've 49 # added the new paths. 50 51 if addToSysPath: 52 oldPluginPath = tuple(_nuke.pluginPath()) 53 54 for i in args: 55 _nuke.pluginAppendPath(i) 56 57 if addToSysPath: 58 newPaths = [ p for p in _nuke.pluginPath() if p not in oldPluginPath ] 59 for path in newPaths: 60 if path not in sys.path: 61 sys.path.append(path)
62 63
64 -def dependencies(nodes, what = _nuke.INPUTS | _nuke.HIDDEN_INPUTS | _nuke.EXPRESSIONS | _nuke.LINKINPUTS):
65 """ List all nodes referred to by the nodes argument. 'what' is an optional integer (see below). 66 You can use the following constants or'ed together to select the types of dependencies that are looked for: 67 \t nuke.EXPRESSIONS = expressions 68 \t nuke.LINKINPUTS = link knob inputs 69 \t nuke.INPUTS = visible input pipes 70 \t nuke.HIDDEN_INPUTS = hidden input pipes. 71 The default is to look for all types of connections. 72 \nExample: 73 n1 = nuke.nodes.Blur() 74 n2 = nuke.nodes.Merge() 75 n2.setInput(0, n1) 76 deps = nuke.dependencies([n2], nuke.INPUTS | nuke.HIDDEN_INPUTS | nuke.EXPRESSIONS)""" 77 78 if type(nodes) != types.TupleType and type(nodes) != types.ListType: 79 nodes = [nodes] 80 81 deps = [] 82 for i in nodes: deps += i.dependencies(what) 83 seen = set() 84 deps = [i for i in deps if i not in seen and not seen.add(i)] 85 86 return deps
87
88 -def dependentNodes(what = _nuke.INPUTS | _nuke.HIDDEN_INPUTS | _nuke.EXPRESSIONS | _nuke.LINKINPUTS, nodes = [], evaluateAll = True):
89 """ List all nodes referred to by the nodes argument. 'what' is an optional integer (see below). 90 You can use the following constants or'ed together to select what types of dependent nodes are looked for: 91 \t nuke.EXPRESSIONS = expressions 92 \t nuke.LINKINPUTS = link knob inputs 93 \t nuke.INPUTS = visible input pipes 94 \t nuke.HIDDEN_INPUTS = hidden input pipes. 95 The default is to look for all types of connections. 96 97 evaluateAll is an optional boolean defaulting to True. When this parameter is true, it forces a re-evaluation of the entire tree. 98 This can be expensive, but otherwise could give incorrect results if nodes are expression-linked. 99 100 \nExample: 101 n1 = nuke.nodes.Blur() 102 n2 = nuke.nodes.Merge() 103 n2.setInput(0, n1) 104 ndeps = nuke.dependentNodes(nuke.INPUTS | nuke.HIDDEN_INPUTS | nuke.EXPRESSIONS, [n1]) 105 106 @param what: Or'ed constant of nuke.EXPRESSIONS, nuke.LINKINPUTS, nuke.INPUTS and nuke.HIDDEN_INPUTS to select the types of dependent nodes. The default is to look for all types of connections. 107 @param evaluateAll: Specifies whether a full tree evaluation will take place. Defaults to True. 108 @return: List of nodes. """ 109 110 if type(nodes) != types.TupleType and type(nodes) != types.ListType: 111 nodes = [nodes] 112 113 deps = [] 114 for i in nodes: 115 deps += i.dependent(what, forceEvaluate = evaluateAll) 116 evaluateAll = False 117 seen = set() 118 deps = [i for i in deps if i not in seen and not seen.add(i)] 119 120 return deps
121
122 -def selectConnectedNodes():
123 """ Selects all nodes in the tree of the selected node. """ 124 allDeps = set() 125 depsList = [_nuke.selectedNode()] 126 evaluateAll = True 127 while depsList: 128 deps = dependencies(depsList, _nuke.INPUTS | _nuke.HIDDEN_INPUTS) 129 deps += dependentNodes(_nuke.INPUTS | _nuke.HIDDEN_INPUTS, depsList, evaluateAll) 130 evaluateAll = False 131 depsList = [i for i in deps if i not in allDeps and not allDeps.add(i)] 132 133 for i in allDeps: i['selected'].setValue(True)
134