Skip to content
This repository was archived by the owner on Oct 10, 2024. It is now read-only.

Commit 6d7fb84

Browse files
committed
Merge branch 'hotfix/nuke-lib'
2 parents 181c7ec + a1eafa1 commit 6d7fb84

File tree

3 files changed

+47
-8
lines changed

3 files changed

+47
-8
lines changed

avalon/nuke/lib.py

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,25 @@ def maintained_selection():
2020
"""
2121
nodes = nuke.allNodes()
2222
previous_selection = nuke.selectedNodes()
23+
24+
# deselect all nodes
25+
reset_selection()
26+
2327
try:
28+
# do the operation
2429
yield
2530
finally:
2631
# unselect all selection in case there is some
2732
reset_selection()
2833
# and select all previously selected nodes
2934
if previous_selection:
30-
for n in nodes:
31-
if n.name() not in previous_selection:
32-
continue
33-
n['selected'].setValue(True)
35+
try:
36+
for n in nodes:
37+
if n not in previous_selection:
38+
continue
39+
n['selected'].setValue(True)
40+
except ValueError as e:
41+
log.warning(e)
3442

3543

3644
def reset_selection():
@@ -48,8 +56,11 @@ def select_nodes(nodes):
4856
"""
4957
assert isinstance(nodes, (list, tuple)), "nodes has to be list or tuple"
5058

51-
for node in nodes:
52-
node['selected'].setValue(True)
59+
try:
60+
for node in nodes:
61+
node['selected'].setValue(True)
62+
except ValueError as e:
63+
log.warning(e)
5364

5465

5566
def add_publish_knob(node):
@@ -197,6 +208,20 @@ def get_avalon_knob_data(node, prefix="ak:"):
197208

198209
return data
199210

211+
def check_subsetname_exists(nodes, subset_name):
212+
"""
213+
Checking if node is not already created to secure there is no duplicity
214+
215+
Arguments:
216+
nodes (list): list of nuke.Node objects
217+
subset_name (str): name we try to find
218+
219+
Returns:
220+
bool: True of False
221+
"""
222+
return next((True for n in nodes
223+
if subset_name in get_avalon_knob_data(n,
224+
["avalon:", "ak:"]).get("subset", "")), False)
200225

201226
def imprint(node, data):
202227
"""Adding `Avalon data` into a node's Avalon Tab/Avalon knob

avalon/nuke/pipeline.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,18 @@ class Creator(api.Creator):
165165
"""
166166
node_color = "0xdfea5dff"
167167

168+
def __init__(self, *args, **kwargs):
169+
super(Creator, self).__init__(*args, **kwargs)
170+
# make sure no duplicity of subsets are in workfile
171+
if lib.check_subsetname_exists(
172+
nuke.allNodes(),
173+
self.data["subset"]):
174+
msg = "The subset name `{0}` is already used on a node in" \
175+
"this workfile.".format(self.data["subset"])
176+
self.log.error(msg + '\n\nPlease use other subset name!')
177+
raise NameError("`{0}: {1}".format(__name__, msg))
178+
return
179+
168180
def process(self):
169181
from nukescripts import autoBackdrop
170182
nodes = list()
@@ -179,6 +191,7 @@ def process(self):
179191

180192
elif len(nodes) >= 2:
181193
bckd_node = autoBackdrop()
194+
bckd_node["name"].setValue("{}_BDN".format(self.name))
182195
bckd_node["tile_color"].setValue(int(self.node_color, 16))
183196
bckd_node["note_font_size"].setValue(24)
184197
bckd_node["label"].setValue("[{}]".format(self.name))
@@ -192,6 +205,7 @@ def process(self):
192205
return
193206
else:
194207
bckd_node = autoBackdrop()
208+
bckd_node["name"].setValue("{}_BDN".format(self.name))
195209
bckd_node["tile_color"].setValue(int(self.node_color, 16))
196210
bckd_node["note_font_size"].setValue(24)
197211
bckd_node["label"].setValue("[{}]".format(self.name))

avalon/pipeline.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -898,8 +898,8 @@ def create(name, asset, family, options=None, data=None):
898898
with host.maintained_selection():
899899
print("Running %s" % plugin)
900900
instance = plugin.process()
901-
except Exception as e:
902-
log.warning(e)
901+
except Exception:
902+
log.warning(traceback.format_exc())
903903
continue
904904
plugins.append(plugin)
905905

0 commit comments

Comments
 (0)