Merge pull request #3763 from pypeclub/feature/OP-3851_Update-nuke-template-build

Nuke: Build workfile by template
This commit is contained in:
Jakub Trllo 2022-09-02 15:41:38 +02:00 committed by GitHub
commit 1d5e691daf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 1088 additions and 38 deletions

View file

@ -78,6 +78,23 @@ class Context:
_project_doc = None
def get_main_window():
"""Acquire Nuke's main window"""
if Context.main_window is None:
from Qt import QtWidgets
top_widgets = QtWidgets.QApplication.topLevelWidgets()
name = "Foundry::UI::DockMainWindow"
for widget in top_widgets:
if (
widget.inherits("QMainWindow")
and widget.metaObject().className() == name
):
Context.main_window = widget
break
return Context.main_window
class Knobby(object):
"""For creating knob which it's type isn't mapped in `create_knobs`
@ -2706,32 +2723,25 @@ class DirmapCache:
@contextlib.contextmanager
def _duplicate_node_temp():
def node_tempfile():
"""Create a temp file where node is pasted during duplication.
This is to avoid using clipboard for node duplication.
"""
duplicate_node_temp_path = os.path.join(
tempfile.gettempdir(),
"openpype_nuke_duplicate_temp_{}".format(os.getpid())
tmp_file = tempfile.NamedTemporaryFile(
mode="w", prefix="openpype_nuke_temp_", suffix=".nk", delete=False
)
# This can happen only if 'duplicate_node' would be
if os.path.exists(duplicate_node_temp_path):
log.warning((
"Temp file for node duplication already exists."
" Trying to remove {}"
).format(duplicate_node_temp_path))
os.remove(duplicate_node_temp_path)
tmp_file.close()
node_tempfile_path = tmp_file.name
try:
# Yield the path where node can be copied
yield duplicate_node_temp_path
yield node_tempfile_path
finally:
# Remove the file at the end
os.remove(duplicate_node_temp_path)
os.remove(node_tempfile_path)
def duplicate_node(node):
@ -2740,7 +2750,7 @@ def duplicate_node(node):
# select required node for duplication
node.setSelected(True)
with _duplicate_node_temp() as filepath:
with node_tempfile() as filepath:
# copy selected to temp filepath
nuke.nodeCopy(filepath)
@ -2815,3 +2825,100 @@ def ls_img_sequence(path):
}
return False
def get_group_io_nodes(nodes):
"""Get the input and the output of a group of nodes."""
if not nodes:
raise ValueError("there is no nodes in the list")
input_node = None
output_node = None
if len(nodes) == 1:
input_node = output_node = nodes[0]
else:
for node in nodes:
if "Input" in node.name():
input_node = node
if "Output" in node.name():
output_node = node
if input_node is not None and output_node is not None:
break
if input_node is None:
raise ValueError("No Input found")
if output_node is None:
raise ValueError("No Output found")
return input_node, output_node
def get_extreme_positions(nodes):
"""Get the 4 numbers that represent the box of a group of nodes."""
if not nodes:
raise ValueError("there is no nodes in the list")
nodes_xpos = [n.xpos() for n in nodes] + \
[n.xpos() + n.screenWidth() for n in nodes]
nodes_ypos = [n.ypos() for n in nodes] + \
[n.ypos() + n.screenHeight() for n in nodes]
min_x, min_y = (min(nodes_xpos), min(nodes_ypos))
max_x, max_y = (max(nodes_xpos), max(nodes_ypos))
return min_x, min_y, max_x, max_y
def refresh_node(node):
"""Correct a bug caused by the multi-threading of nuke.
Refresh the node to make sure that it takes the desired attributes.
"""
x = node.xpos()
y = node.ypos()
nuke.autoplaceSnap(node)
node.setXYpos(x, y)
def refresh_nodes(nodes):
for node in nodes:
refresh_node(node)
def get_names_from_nodes(nodes):
"""Get list of nodes names.
Args:
nodes(List[nuke.Node]): List of nodes to convert into names.
Returns:
List[str]: Name of passed nodes.
"""
return [
node.name()
for node in nodes
]
def get_nodes_by_names(names):
"""Get list of nuke nodes based on their names.
Args:
names (List[str]): List of node names to be found.
Returns:
List[nuke.Node]: List of nodes found by name.
"""
return [
nuke.toNode(name)
for name in names
]