From 430821326de1a97103625f0cf08ea330bb5ee94f Mon Sep 17 00:00:00 2001 From: ElgoogUdiab Date: Sun, 16 Mar 2025 15:49:19 +0800 Subject: [PATCH] Fix: wrong active object after creation/before deletion --- addon.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/addon.py b/addon.py index bd14680..d4bc3d4 100644 --- a/addon.py +++ b/addon.py @@ -293,7 +293,8 @@ class BlenderMCPServer: raise ValueError(f"Unsupported object type: {type}") # Get the created object - obj = bpy.context.active_object + bpy.context.view_layer.update() + obj = bpy.context.view_layer.objects.active # Rename the object if a name is provided if name: @@ -359,9 +360,8 @@ class BlenderMCPServer: obj_name = obj.name # Select and delete the object - bpy.ops.object.select_all(action='DESELECT') - obj.select_set(True) - bpy.ops.object.delete() + if obj: + bpy.data.objects.remove(obj, do_unlink=True) return {"deleted": obj_name}