Node Wrangler: Improved accuracy on Align Nodes operator #104551

Open
quackarooni wants to merge 18 commits from quackarooni/blender-addons:nw_rework_align_nodes into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
2 changed files with 59 additions and 42 deletions
Showing only changes of commit cbe34040be - Show all commits

View File

@ -26,7 +26,7 @@ from .utils.draw import draw_callback_nodeoutline
from .utils.paths import match_files_to_socket_names, split_into_components from .utils.paths import match_files_to_socket_names, split_into_components
from .utils.nodes import (node_mid_pt, autolink, node_at_pos, get_active_tree, get_nodes_links, is_viewer_socket, from .utils.nodes import (node_mid_pt, autolink, node_at_pos, get_active_tree, get_nodes_links, is_viewer_socket,
is_viewer_link, get_group_output_node, get_output_location, force_update, get_internal_socket, is_viewer_link, get_group_output_node, get_output_location, force_update, get_internal_socket,
nw_check, NWBase, get_first_enabled_output, is_visible_socket, viewer_socket_name) nw_check, NWBase, get_first_enabled_output, is_visible_socket, temporary_unframe, viewer_socket_name)
class NWLazyMix(Operator, NWBase): class NWLazyMix(Operator, NWBase):
@ -2352,6 +2352,7 @@ class NWAlignNodes(Operator, NWBase):
active_node = context.active_node active_node = context.active_node
margin = self.margin margin = self.margin
with temporary_unframe(nodes=selection):
active_loc = None active_loc = None
if active_node in selection: if active_node in selection:
active_loc = copy(active_node.location) # make a copy, not a reference active_loc = copy(active_node.location) # make a copy, not a reference

View File

@ -250,6 +250,22 @@ def is_visible_socket(socket):
return not socket.hide and socket.enabled and socket.type != 'CUSTOM' return not socket.hide and socket.enabled and socket.type != 'CUSTOM'
class temporary_unframe(): # Context manager for temporarily unparenting nodes from their frames
def __init__(self, nodes):
self.parent_dict = {}
for node in nodes:
if node.parent is not None:
self.parent_dict[node] = node.parent
node.parent = None
def __enter__(self):
return self
def __exit__(self, type, value, traceback):
for node, parent in self.parent_dict.items():
node.parent = parent
class NWBase: class NWBase:
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):