Merge pull request #97 from davidebbo/return-exec-output
Returns execute_code stdout
This commit is contained in:
commit
bcc1ba1864
12
addon.py
12
addon.py
@ -12,6 +12,8 @@ import traceback
|
|||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
from bpy.props import StringProperty, IntProperty, BoolProperty, EnumProperty
|
from bpy.props import StringProperty, IntProperty, BoolProperty, EnumProperty
|
||||||
|
import io
|
||||||
|
from contextlib import redirect_stdout
|
||||||
|
|
||||||
bl_info = {
|
bl_info = {
|
||||||
"name": "Blender MCP",
|
"name": "Blender MCP",
|
||||||
@ -334,8 +336,14 @@ class BlenderMCPServer:
|
|||||||
try:
|
try:
|
||||||
# Create a local namespace for execution
|
# Create a local namespace for execution
|
||||||
namespace = {"bpy": bpy}
|
namespace = {"bpy": bpy}
|
||||||
exec(code, namespace)
|
|
||||||
return {"executed": True}
|
# Capture stdout during execution, and return it as result
|
||||||
|
capture_buffer = io.StringIO()
|
||||||
|
with redirect_stdout(capture_buffer):
|
||||||
|
exec(code, namespace)
|
||||||
|
|
||||||
|
captured_output = capture_buffer.getvalue()
|
||||||
|
return {"executed": True, "result": captured_output}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise Exception(f"Code execution error: {str(e)}")
|
raise Exception(f"Code execution error: {str(e)}")
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user