[Bf-extensions-cvs] [f6c8e8e] master: Node Wrangler: Fix everything breaking in 2nd level node groups

Greg noreply at git.blender.org
Mon Aug 8 22:41:11 CEST 2016


Commit: f6c8e8e2c5cb951d186138e0c50a4850b6172786
Author: Greg
Date:   Mon Aug 8 22:35:26 2016 +0200
Branches: master
https://developer.blender.org/rBAf6c8e8e2c5cb951d186138e0c50a4850b6172786

Node Wrangler: Fix everything breaking in 2nd level node groups

When using basically any NW function inside a 2nd (or higher) level nested node group, it would fetch instead the 1st level nodes.
Logic is now simplified and improved to find the active tree no matter how far down the rabbit hole you go.

===================================================================

M	node_wrangler.py

===================================================================

diff --git a/node_wrangler.py b/node_wrangler.py
index ea3b6ac..aa96a0c 100644
--- a/node_wrangler.py
+++ b/node_wrangler.py
@@ -971,26 +971,18 @@ def draw_callback_nodeoutline(self, context, mode):
 
 
 def get_nodes_links(context):
-    space = context.space_data
-    tree = space.node_tree
-    nodes = tree.nodes
-    links = tree.links
-    active = nodes.active
-    context_active = context.active_node
-    # check if we are working on regular node tree or node group is currently edited.
-    # if group is edited - active node of space_tree is the group
-    # if context.active_node != space active node - it means that the group is being edited.
-    # in such case we set "nodes" to be nodes of this group, "links" to be links of this group
-    # if context.active_node == space.active_node it means that we are not currently editing group
-    is_main_tree = True
-    if active:
-        is_main_tree = context_active == active
-    if not is_main_tree:  # if group is currently edited
-        tree = active.node_tree
-        nodes = tree.nodes
-        links = tree.links
-
-    return nodes, links
+    tree = context.space_data.node_tree
+
+    # Get nodes from currently edited tree.
+    # If user is editing a group, space_data.node_tree is still the base level (outside group).
+    # context.active_node is in the group though, so if space_data.node_tree.nodes.active is not
+    # the same as context.active_node, the user is in a group.
+    # Check recursively until we find the real active node_tree:
+    if tree.nodes.active:
+        while tree.nodes.active != context.active_node:
+            tree = tree.nodes.active.node_tree
+
+    return tree.nodes, tree.links
 
 
 # Addon prefs



More information about the Bf-extensions-cvs mailing list