1
2
3 import nuke
4 import os.path
5 import re
6
7 __NODES_FOR_VERSION = ( "Read",
8 "Write",
9 "Precomp",
10 "DeepRead",
11 "DeepWrite",
12 )
13
15 """Extract version information from filenames used by DD (and Weta, apparently)
16 These are _v# or /v# or .v# where v is a prefix string, in our case
17 we use "v" for render version and "c" for camera track version.
18 See the version.py and camera.py plugins for usage."""
19
20 if string is None:
21 raise ValueError, "Empty version string - no match"
22
23 regex = "[/_.]"+prefix+"\d+"
24 matches = re.findall(regex, string, re.IGNORECASE)
25 if not len(matches):
26 msg = "No \"_"+prefix+"#\" found in \""+string+"\""
27 raise ValueError, msg
28 return (matches[-1:][0][1], re.search("\d+", matches[-1:][0]).group())
29
31 """Changes version information from filenames used by DD (and Weta, apparently)
32 These are _v# or /v# or .v# where v is a prefix string, in our case
33 we use "v" for render version and "c" for camera track version.
34 See the version.py and camera.py plugins for usage."""
35
36 regex = "[/_.]"+prefix+"\d+"
37 matches = re.findall(regex, string, re.IGNORECASE)
38 if not len(matches):
39 return ""
40
41
42 matches = filter(lambda s: int(s[2:]) == oldintval, matches)
43
44
45 for match in matches:
46
47 fmt = "%%(#)0%dd" % (len(match) - 2)
48 newfullvalue = match[0] + prefix + str(fmt % {"#": newintval})
49 string = re.sub(match, newfullvalue, string)
50 return string
51
53 """All new version_up that uses the version_get/set functions.
54 This script takes the render version up one in selected iread/writes."""
55
56 n = nuke.selectedNodes()
57 for i in n:
58 _class = i.Class()
59
60 if _class in __NODES_FOR_VERSION:
61 fileKnob = i['file']
62 proxyKnob = i.knob('proxy')
63 try:
64 (prefix, v) = version_get(fileKnob.value(), 'v')
65 v = int(v)
66 fileKnob.setValue(version_set(fileKnob.value(), prefix, v, v + 1))
67 except ValueError:
68
69
70
71 if proxyKnob and proxyKnob.value():
72 (prefix, v) = version_get(proxyKnob.value(), 'v')
73 v = int(v)
74
75 if proxyKnob and proxyKnob.value():
76 proxyKnob.setValue(version_set(proxyKnob.value(), prefix, v, v + 1))
77
78 nuke.root().setModified(True)
79
81 """All new version_down that uses the version_get/set functions.
82 This script takes the render version up one in selected iread/writes."""
83
84 n = nuke.selectedNodes()
85 for i in n:
86 _class = i.Class()
87
88 if _class in __NODES_FOR_VERSION:
89 fileKnob = i['file']
90 proxyKnob = i.knob('proxy')
91 try:
92 (prefix, v) = version_get(fileKnob.value(), 'v')
93 v = int(v)
94 fileKnob.setValue(version_set(fileKnob.value(), prefix, v, v - 1))
95 except ValueError:
96
97
98
99 if proxyKnob and proxyKnob.value():
100 (prefix, v) = version_get(proxyKnob.value(), 'v')
101 v = int(v)
102 if proxyKnob and proxyKnob.value():
103 proxyKnob.setValue(version_set(proxyKnob.value(), prefix, v, v - 1))
104 nuke.root().setModified(True)
105
107 """Like version_up, but only goes up to the highest numbered version
108 that exists.
109
110 Works on all selected Read nodes, or all Read nodes if nothing is
111 selected.
112
113 Does not modify Write nodes."""
114
115 class __KnobValueReplacer(object):
116 def loop(self, knob):
117 while True:
118 oVersion = knob.value()
119 try:
120 (prefix, v) = version_get(oVersion, 'v')
121 v = int(v)
122 nVersion = version_set(oVersion, prefix, v, v + 1)
123 knob.setValue(nVersion)
124 if not os.path.exists(knob.evaluate()):
125 knob.setValue(oVersion)
126 return
127 nuke.root().setModified(True)
128 except ValueError:
129 return
130
131 nodes = nuke.selectedNodes()
132 if not nodes: nodes = nuke.allNodes()
133 n = [i for i in nodes if i.Class() == "Read"]
134 for i in n:
135 __KnobValueReplacer().loop(i['file'])
136 __KnobValueReplacer().loop(i['proxy'])
137