Geometry Nodes: shortcuts for viewer nodes
Implement shortcuts for viewer nodes. Viewer nodes are now activated using the operator `bpy.ops.node.activate_viewer()` instead of activating the viewer by setting the node to active. This also unifies the behavior with viewer shortcuts in the compositor (see attachment in the original PR). Pull Request: https://projects.blender.org/blender/blender/pulls/134555
This commit is contained in:
@@ -565,7 +565,7 @@ class NODE_OT_viewer_shortcut_set(Operator):
|
||||
(space is not None) and
|
||||
space.type == 'NODE_EDITOR' and
|
||||
space.node_tree is not None and
|
||||
space.tree_type == 'CompositorNodeTree'
|
||||
space.tree_type in {'CompositorNodeTree', 'GeometryNodeTree'}
|
||||
)
|
||||
|
||||
def execute(self, context):
|
||||
@@ -580,7 +580,6 @@ class NODE_OT_viewer_shortcut_set(Operator):
|
||||
|
||||
# Only viewer nodes can be set to favorites. However, the user can
|
||||
# create a new favorite viewer by selecting any node and pressing ctrl+1.
|
||||
old_active = nodes.active
|
||||
if fav_node.type == 'VIEWER':
|
||||
viewer_node = fav_node
|
||||
else:
|
||||
@@ -600,10 +599,8 @@ class NODE_OT_viewer_shortcut_set(Operator):
|
||||
)
|
||||
return {'CANCELLED'}
|
||||
|
||||
# Use the node active status to enable this viewer node and disable others.
|
||||
nodes.active = viewer_node
|
||||
if old_active.type != 'VIEWER':
|
||||
nodes.active = old_active
|
||||
with bpy.context.temp_override(node=viewer_node):
|
||||
bpy.ops.node.activate_viewer()
|
||||
|
||||
viewer_node.ui_shortcut = self.viewer_index
|
||||
self.report({'INFO'}, "Assigned shortcut {:d} to {:s}".format(self.viewer_index, viewer_node.name))
|
||||
@@ -629,7 +626,7 @@ class NODE_OT_viewer_shortcut_get(Operator):
|
||||
(space is not None) and
|
||||
space.type == 'NODE_EDITOR' and
|
||||
space.node_tree is not None and
|
||||
space.tree_type == 'CompositorNodeTree'
|
||||
space.tree_type in {'CompositorNodeTree', 'GeometryNodeTree'}
|
||||
)
|
||||
|
||||
def execute(self, context):
|
||||
@@ -645,11 +642,8 @@ class NODE_OT_viewer_shortcut_get(Operator):
|
||||
self.report({'INFO'}, "Shortcut {:d} is not assigned to a Viewer node yet".format(self.viewer_index))
|
||||
return {'CANCELLED'}
|
||||
|
||||
# Use the node active status to enable this viewer node and disable others.
|
||||
old_active = nodes.active
|
||||
nodes.active = viewer_node
|
||||
if old_active.type != "VIEWER":
|
||||
nodes.active = old_active
|
||||
with bpy.context.temp_override(node=viewer_node):
|
||||
bpy.ops.node.activate_viewer()
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user