fixed the create_object nonetype error
This commit is contained in:
parent
5e0f87cbc1
commit
9c299304ce
24
addon.py
24
addon.py
@ -266,9 +266,11 @@ class BlenderMCPServer:
|
|||||||
align="WORLD", major_segments=48, minor_segments=12, mode="MAJOR_MINOR",
|
align="WORLD", major_segments=48, minor_segments=12, mode="MAJOR_MINOR",
|
||||||
major_radius=1.0, minor_radius=0.25, abso_major_rad=1.25, abso_minor_rad=0.75, generate_uvs=True):
|
major_radius=1.0, minor_radius=0.25, abso_major_rad=1.25, abso_minor_rad=0.75, generate_uvs=True):
|
||||||
"""Create a new object in the scene"""
|
"""Create a new object in the scene"""
|
||||||
# Deselect all objects
|
try:
|
||||||
|
# Deselect all objects first
|
||||||
bpy.ops.object.select_all(action='DESELECT')
|
bpy.ops.object.select_all(action='DESELECT')
|
||||||
|
|
||||||
|
# Create the object based on type
|
||||||
if type == "CUBE":
|
if type == "CUBE":
|
||||||
bpy.ops.mesh.primitive_cube_add(location=location, rotation=rotation, scale=scale)
|
bpy.ops.mesh.primitive_cube_add(location=location, rotation=rotation, scale=scale)
|
||||||
elif type == "SPHERE":
|
elif type == "SPHERE":
|
||||||
@ -302,14 +304,26 @@ class BlenderMCPServer:
|
|||||||
else:
|
else:
|
||||||
raise ValueError(f"Unsupported object type: {type}")
|
raise ValueError(f"Unsupported object type: {type}")
|
||||||
|
|
||||||
# Get the created object
|
# Force update the view layer
|
||||||
bpy.context.view_layer.update()
|
bpy.context.view_layer.update()
|
||||||
|
|
||||||
|
# Get the active object (which should be our newly created object)
|
||||||
obj = bpy.context.view_layer.objects.active
|
obj = bpy.context.view_layer.objects.active
|
||||||
|
|
||||||
# Rename the object if a name is provided
|
# If we don't have an active object, something went wrong
|
||||||
|
if obj is None:
|
||||||
|
raise RuntimeError("Failed to create object - no active object")
|
||||||
|
|
||||||
|
# Make sure it's selected
|
||||||
|
obj.select_set(True)
|
||||||
|
|
||||||
|
# Rename if name is provided
|
||||||
if name:
|
if name:
|
||||||
obj.name = name
|
obj.name = name
|
||||||
|
if obj.data:
|
||||||
|
obj.data.name = name
|
||||||
|
|
||||||
|
# Return the object info
|
||||||
result = {
|
result = {
|
||||||
"name": obj.name,
|
"name": obj.name,
|
||||||
"type": obj.type,
|
"type": obj.type,
|
||||||
@ -323,6 +337,10 @@ class BlenderMCPServer:
|
|||||||
result["world_bounding_box"] = bounding_box
|
result["world_bounding_box"] = bounding_box
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error in create_object: {str(e)}")
|
||||||
|
traceback.print_exc()
|
||||||
|
return {"error": str(e)}
|
||||||
|
|
||||||
def modify_object(self, name, location=None, rotation=None, scale=None, visible=None):
|
def modify_object(self, name, location=None, rotation=None, scale=None, visible=None):
|
||||||
"""Modify an existing object in the scene"""
|
"""Modify an existing object in the scene"""
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user