Nodes: Swap Node Operator
Implement a native method to swap between different node and zone types. This implementation repurposes the existing menu definitions as base classes, from which both an "Add" and a "Swap" version would be generated from. This allows both menus to have the same layout, but use their own operators for handling the different node/zone types. In this PR, support for all node editors has been implemented. Invoking the menu is currently bound to `Shift + S`, same as the old implementation in Node Wrangler. Since "Swap" is implemented as a regular menu, features that menus already have such as type-to-search and adding to Quick Favorites don't require any extra caveats to consider. Resolves #133452 Pull Request: https://projects.blender.org/blender/blender/pulls/143997
This commit is contained in:
@@ -132,14 +132,14 @@ class MyCustomNode(MyCustomTreeNode, Node):
|
||||
return "I am a custom node"
|
||||
|
||||
|
||||
# Add custom nodes to the Add menu.
|
||||
# Add custom nodes to the Add & Swap menu.
|
||||
def draw_add_menu(self, context):
|
||||
layout = self.layout
|
||||
if context.space_data.tree_type != MyCustomTree.bl_idname:
|
||||
# Avoid adding nodes to built-in node tree
|
||||
return
|
||||
# Add nodes to the layout. Can use submenus, separators, etc. as in any other menu.
|
||||
node_add_menu.add_node_type(layout, "CustomNodeType")
|
||||
self.node_operator(layout, "CustomNodeType")
|
||||
|
||||
|
||||
classes = (
|
||||
@@ -156,10 +156,12 @@ def register():
|
||||
register_class(cls)
|
||||
|
||||
bpy.types.NODE_MT_add.append(draw_add_menu)
|
||||
bpy.types.NODE_MT_swap.append(draw_add_menu)
|
||||
|
||||
|
||||
def unregister():
|
||||
bpy.types.NODE_MT_add.remove(draw_add_menu)
|
||||
bpy.types.NODE_MT_swap.remove(draw_add_menu)
|
||||
|
||||
from bpy.utils import unregister_class
|
||||
for cls in reversed(classes):
|
||||
|
||||
Reference in New Issue
Block a user