Page MenuHome

Node Wrangler: Switch Type shows empty menu in Geometry Nodes
Confirmed, HighPublicBUG

Description

System Information
Operating system: Windows-10-10.0.19043-SP0 64 Bits
Graphics card: Radeon RX 570 Series ATI Technologies Inc. 4.5.14800 Core Profile Context 22.5.1 30.0.15021.11005

Blender Version
Broken: version: 3.4.0 Alpha, branch: master, commit date: 2022-09-30 22:40, hash: rB206dead86058
Worked: version: 3.4.0 Alpha, branch: master, commit date: 2022-09-26 00:52, hash: rB3a7dc572dc9b

Probably caused by 837144b4577f. This is the only relevant commit from Blender side between working and broken versions.

Short description of error
Node Wrangler's Switch Type shows empty menu in Geometry Nodes. It works in Shader and Compositor node.

Exact steps for others to reproduce the error

  • Add Geometry Nodes to object
  • Select any node, try Switch Type (Shift + S). Only shows empty menu
  • The same with Switch Type button from sidebar

Event Timeline

user1 (user1) closed this task as Archived.Oct 1 2022, 2:06 PM
user1 (user1) added a subscriber: user1 (user1).

Not sure, but you should be able to change the tag to something like "addons", since nodewrangler is an addon, right? Apart from that, i confirm that the wrangler is broken.

you should be able to change the tag to something like "addons"

Sure. I think this is caused by a change from Blender side, so I'll leave BF Blender too.

But why did you archived this?

Germano Cavalcante (mano-wii) reopened this task as Confirmed.Oct 3 2022, 4:10 PM
Germano Cavalcante (mano-wii) changed the subtype of this task from "Report" to "Bug".
Wannes Malfait (Wannes) triaged this task as High priority.Wed, Nov 16, 1:15 PM

This is a regression and should be fixed before 3.4 gets released.
Caused by rB837144b4577f: Nodes: Use plain menus for geometry nodes add menu (as far as I can tell).
@Hans Goudey (HooglyBoogly) Any idea on how to fix this?

This hack makes the add menu behave like the switch node type menu, but I don't see a way to make this work from inside node wrangler without basically duplicating all the code in node_add_menu_geometry.py and node_add_menu.py.

diff --git a/release/scripts/startup/bl_ui/node_add_menu.py b/release/scripts/startup/bl_ui/node_add_menu.py
index 873dbd533a5..4e76bfedd60 100644
--- a/release/scripts/startup/bl_ui/node_add_menu.py
+++ b/release/scripts/startup/bl_ui/node_add_menu.py
@@ -13,9 +13,9 @@ def add_node_type(layout, node_type, *, label=None):
     if not label:
         label = bl_rna.name if bl_rna else iface_("Unknown")
     translation_context = bl_rna.translation_context if bl_rna else i18n_contexts.default
-    props = layout.operator("node.add_node", text=label, text_ctxt=translation_context)
-    props.type = node_type
-    props.use_transform = True
+    props = layout.operator("node.nw_switch_node_type", text=label, text_ctxt=translation_context)
+    props.to_type = node_type
+    props.node_group = ''
     return props
 
 
@@ -54,9 +54,7 @@ def draw_node_group_add_menu(context, layout):
             layout.separator()
             for group in groups:
                 props = add_node_type(layout, node_tree_group_type[group.bl_idname], label=group.name)
-                ops = props.settings.add()
-                ops.name = "node_tree"
-                ops.value = "bpy.data.node_groups[%r]" % group.name
+                props.node_group = group.name
 
 
 def draw_assets_for_catalog(layout, catalog_path):
diff --git a/node_wrangler.py b/node_wrangler.py
index 5932388f..03a911f5 100644
--- a/node_wrangler.py
+++ b/node_wrangler.py
@@ -1707,7 +1707,7 @@ class NWReloadImages(Operator):
 
 class NWSwitchNodeType(Operator, NWBase):
     """Switch type of selected nodes """
-    bl_idname = "node.nw_swtch_node_type"
+    bl_idname = "node.nw_switch_node_type"
     bl_label = "Switch Node Type"
     bl_options = {'REGISTER', 'UNDO'}
 
@@ -1716,6 +1716,11 @@ class NWSwitchNodeType(Operator, NWBase):
         default = '',
     )
 
+    node_group: StringProperty(
+        name="Node group name",
+        default = '',
+    )
+
     def execute(self, context):
         to_type = self.to_type
         if len(to_type) == 0:
@@ -1735,6 +1740,10 @@ class NWSwitchNodeType(Operator, NWBase):
                      n.rna_type.identifier not in src_excludes and
                      n.rna_type.identifier != to_type]:
             new_node = nodes.new(to_type)
+
+            if self.node_group != '':
+                new_node.node_tree = bpy.data.node_groups[self.node_group]
+                    
             for attr in attrs_to_pass:
                 if hasattr(node, attr) and hasattr(new_node, attr):
                     setattr(new_node, attr, getattr(node, attr))

Sorry for the delayed response here.
I'm not sure if I'm going to have time to look into this today. I'm also not that experienced with the Python API so I'm not exactly sure how to do this at the moment, but the approach I'd try is scanning over the nodes in bpy.types. From there I assume we could check if the type is compatible with the current tree. If the operator needs to know the default sockets of the node, I assume we would have to add a dummy node to check.

Sorry for the delayed response here.
I'm not sure if I'm going to have time to look into this today. I'm also not that experienced with the Python API so I'm not exactly sure how to do this at the moment, but the approach I'd try is scanning over the nodes in bpy.types. From there I assume we could check if the type is compatible with the current tree. If the operator needs to know the default sockets of the node, I assume we would have to add a dummy node to check.

Problem is that you can't build the menu from bpy.types information. You don't have information on the way the nodes are organized into submenus. The operator works in two steps:

  • A menu is shown (essentially identical to the add menu) from which the user can select a node type. This is no longer possible with the current python API without copy pasting 90% of the code in node_add_menu_geometry.py
  • This node type is then used to call the nw_switch_node_type operator which does the actual "work". This operator is not really affected by this regression.

If there was some way to pass your own "on_click" operator to the "add menu" via the python API, then the problem would be gone.