nukescripts.searchreplace

Package nukescripts :: Module searchreplace |
[hide private]
[frames] | no frames]

# Source Code for Module nukescripts.searchreplace

     1  # Copyright (c) 2009 The Foundry Visionmongers Ltd.  All Rights Reserved.
     2
     3  import nuke, re
     4
     5 -def __NodeHasKnobWithName(node, name):
     6    try:
     7      node[name]
     8    except NameError:
     9      return False
    10    else:
    11      return True
    12
    13 -def __NodeHasFileKnob(node):
    14    return __NodeHasKnobWithName(node, 'file')
    15
    16 -def __NodeHasProxyKnob(node):
    17    return __NodeHasKnobWithName(node, 'proxy')
    18
    19 -def __ReplaceKnobValue(searchstr, replacestr, knob):
    20    v = knob.value()
    21    if v:
    22      repl = re.sub(searchstr, replacestr, v)
    23      knob.setValue(repl)
    24
    25 -def search_replace():
    26    """ Search/Replace in Reads and Writes. """
    27    fileKnobNodes = [i for i in nuke.selectedNodes() if __NodeHasFileKnob(i)]
    28    proxyKnobNodes = [i for i in nuke.selectedNodes() if __NodeHasProxyKnob(i)]
    29    if not fileKnobNodes and not proxyKnobNodes: raise ValueError, "No nodes selected"
    30
    31    p = nuke.Panel("Search/Replace in Reads and Writes")
    32    p.addSingleLineInput("Search for:", "rgbea")
    33    p.addSingleLineInput("Replace with:", "rgbea")
    34    success = p.show()
    35    if success == 1:
    36      searchstr = p.value("Search for:")
    37      replacestr = p.value("Replace with:")
    38
    39      for i in fileKnobNodes: __ReplaceKnobValue(searchstr, replacestr, i['file'])
    40      for i in proxyKnobNodes: __ReplaceKnobValue(searchstr, replacestr, i['proxy'])
    41