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):
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.INPUTS = visible input pipes 69 \t nuke.HIDDEN_INPUTS = hidden input pipes. 70 The default is to look for all types of connections. 71 \nExample: 72 n1 = nuke.nodes.Blur() 73 n2 = nuke.nodes.Merge() 74 n2.setInput(0, n1) 75 deps = nuke.dependencies([n2], nuke.INPUTS | nuke.HIDDEN_INPUTS | nuke.EXPRESSIONS)""" 76 77 if type(nodes) != types.TupleType and type(nodes) != types.ListType: 78 nodes = [nodes] 79 80 deps = [] 81 for i in nodes: deps += i.dependencies(what) 82 seen = set() 83 deps = [i for i in deps if i not in seen and not seen.add(i)] 84 85 return deps
86
87 -def dependentNodes(what = _nuke.INPUTS | _nuke.HIDDEN_INPUTS | _nuke.EXPRESSIONS, nodes = [], evaluateAll = True):
88 """ List all nodes referred to by the nodes argument. 'what' is an optional integer (see below). 89 You can use the following constants or'ed together to select what types of dependent nodes are looked for: 90 \t nuke.EXPRESSIONS = expressions 91 \t nuke.INPUTS = visible input pipes 92 \t nuke.HIDDEN_INPUTS = hidden input pipes. 93 The default is to look for all types of connections. 94 95 evaluateAll is an optional boolean defaulting to True. When this parameter is true, it forces a re-evaluation of the entire tree. 96 This can be expensive, but otherwise could give incorrect results if nodes are expression-linked. 97 98 \nExample: 99 n1 = nuke.nodes.Blur() 100 n2 = nuke.nodes.Merge() 101 n2.setInput(0, n1) 102 ndeps = nuke.dependentNodes(nuke.INPUTS | nuke.HIDDEN_INPUTS | nuke.EXPRESSIONS, [n1]) 103 104 @param what: Or'ed constant of nuke.EXPRESSIONS, nuke.INPUTS and nuke.HIDDEN_INPUTS to select the types of dependent nodes. The default is to look for all types of connections. 105 @param evaluateAll: Specifies whether a full tree evaluation will take place. Defaults to True. 106 @return: List of nodes. """ 107 108 if type(nodes) != types.TupleType and type(nodes) != types.ListType: 109 nodes = [nodes] 110 111 deps = [] 112 for i in nodes: 113 deps += i.dependent(what, forceEvaluate = evaluateAll) 114 evaluateAll = False 115 seen = set() 116 deps = [i for i in deps if i not in seen and not seen.add(i)] 117 118 return deps
119
120 -def selectConnectedNodes():
121 """ Selects all nodes in the tree of the selected node. """ 122 allDeps = set() 123 depsList = [_nuke.selectedNode()] 124 evaluateAll = True 125 while depsList: 126 deps = dependencies(depsList, _nuke.INPUTS | _nuke.HIDDEN_INPUTS) 127 deps += dependentNodes(_nuke.INPUTS | _nuke.HIDDEN_INPUTS, depsList, evaluateAll) 128 evaluateAll = False 129 depsList = [i for i in deps if i not in allDeps and not allDeps.add(i)] 130 131 for i in allDeps: i['selected'].setValue(True)
132