Blender: removeNode and removeModifier on an absent target push no undo step

NodeActions.changed says whether the last action wrote; run_intent pushes the labelled
step only when it did (the run_intent half rode in the previous commit's blender_target.py).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-11-27 20:30:27 +01:00
commit 8f5a660964
2 changed files with 12 additions and 1 deletions

View file

@ -121,8 +121,10 @@ class NodeActions:
def __init__(self, bpy_module: Any):
self.bpy = bpy_module
self.changed = False # whether the last execute wrote anything: an absent-target removal does not
def execute(self, action: str, command: dict[str, Any]) -> tuple[str, str]:
self.changed = True
return getattr(self, "_" + action)(command)
# tree and node lookup
@ -236,6 +238,7 @@ class NodeActions:
raise ActionRefused(f"{node_id!r} is the group's own input/output node and stays.")
node = next((n for n in tree.nodes if n.get("brokkr_id") == node_id), None)
if node is None:
self.changed = False
return f"Node {node_id!r} was already absent.", node_id
tree.nodes.remove(node) # Blender drops the node's links with it
return "Node removed.", node_id
@ -305,6 +308,7 @@ class NodeActions:
raise ActionRefused("modifierName must be a string of at most 255 characters.")
modifier = obj.modifiers.get(name)
if modifier is None:
self.changed = False
return f"Modifier {name!r} was already absent.", obj.name
if modifier.type != "NODES":
raise ActionRefused(f"{name!r} is not a Geometry Nodes modifier; only those are removed here.")

View file

@ -544,8 +544,11 @@ class NodeActionTests(unittest.TestCase):
tree = self.chain()
self.accepted(action="removeNode", treeKey="G", id="b")
self.assertEqual([n.get("brokkr_id") for n in tree.nodes], ["gin", "gout", "a", "c"])
pushes = len(self.bpy.undo.pushes)
again = self.accepted(action="removeNode", treeKey="G", id="b")
self.assertIn("already absent", again["message"])
self.assertEqual(len(self.bpy.undo.pushes), pushes) # nothing changed: no undo step
self.assertEqual(again["undoLabel"], "")
for keep in ("gin", "gout"):
self.refused(action="removeNode", treeKey="G", id=keep)
self.refused(action="removeNode", treeKey="Nope", id="a")
@ -575,7 +578,11 @@ class NodeActionTests(unittest.TestCase):
self.accepted(action="removeModifier", objectName="Host", modifierName="GN")
self.assertEqual([m.name for m in host.modifiers], ["Sub"])
self.assertEqual(host.tagged, tags + 1)
self.assertIn("already absent", self.accepted(action="removeModifier", objectName="Host", modifierName="GN")["message"])
pushes = len(self.bpy.undo.pushes)
again = self.accepted(action="removeModifier", objectName="Host", modifierName="GN")
self.assertIn("already absent", again["message"])
self.assertEqual(len(self.bpy.undo.pushes), pushes)
self.assertEqual(again["undoLabel"], "")
self.refused(action="removeModifier", objectName="Nope", modifierName="GN")
for bad in (["x"], "x" * 256, "a\0b", 5):
self.refused(action="removeModifier", objectName="Host", modifierName=bad)