nuke.overrides

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    \nExample:
     95    n1 = nuke.nodes.Blur()
     96    n2 = nuke.nodes.Merge()
     97    n2.setInput(0, n1)
     98    ndeps = nuke.dependentNodes(nuke.INPUTS | nuke.HIDDEN_INPUTS | nuke.EXPRESSIONS, [n1])"""
     99
    100    if type(nodes) != types.TupleType and type(nodes) != types.ListType:
    101      nodes = [nodes]
    102
    103    deps = []
    104    for i in nodes:
    105      deps += i.dependent(what, forceEvaluate = evaluateAll)
    106      evaluateAll = False
    107    seen = set()
    108    deps = [i for i in deps if i not in seen and not seen.add(i)]
    109
    110    return deps
    111
    112 -def selectConnectedNodes():
    113    """ Selects all nodes in the tree of the selected node. """
    114    allDeps = set()
    115    depsList = [_nuke.selectedNode()]
    116    evaluateAll = True
    117    while depsList:
    118      deps = dependencies(depsList, _nuke.INPUTS | _nuke.HIDDEN_INPUTS)
    119      deps += dependentNodes(_nuke.INPUTS | _nuke.HIDDEN_INPUTS, depsList, evaluateAll)
    120      evaluateAll = False
    121      depsList = [i for i in deps if i not in allDeps and not allDeps.add(i)]
    122
    123    for i in allDeps: i['selected'].setValue(True)
    124