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