suwoodblender/blenderpython/debug_test.py

205 lines
6.2 KiB
Python
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
SUWImpl Blender 调试测试脚本
专门用于排查在Blender中运行无反应的问题
"""
print("🚀 开始调试测试...")
print("=" * 50)
# 步骤1: 基本环境检查
print("\n📝 步骤1: 基本环境检查")
try:
import sys
import os
print(f"✅ Python版本: {sys.version}")
print(f"✅ 当前工作目录: {os.getcwd()}")
print(f"✅ 脚本位置: {__file__}")
except Exception as e:
print(f"❌ 基本环境检查失败: {e}")
# 步骤2: Blender API检查
print("\n📝 步骤2: Blender API检查")
try:
import bpy
print(f"✅ Blender版本: {bpy.app.version_string}")
print(f"✅ 当前场景: {bpy.context.scene.name}")
print(f"✅ 对象数量: {len(bpy.context.scene.objects)}")
BLENDER_AVAILABLE = True
except ImportError as e:
print(f"❌ Blender API不可用: {e}")
BLENDER_AVAILABLE = False
except Exception as e:
print(f"❌ Blender API错误: {e}")
BLENDER_AVAILABLE = False
# 步骤3: 路径设置和检查
print("\n📝 步骤3: 路径设置和检查")
try:
current_dir = os.path.dirname(os.path.abspath(__file__))
print(f"📁 脚本目录: {current_dir}")
if current_dir not in sys.path:
sys.path.append(current_dir)
print(f"✅ 已添加路径到sys.path")
else:
print(f" 路径已在sys.path中")
# 检查suw_impl.py是否存在
suw_impl_path = os.path.join(current_dir, "suw_impl.py")
if os.path.exists(suw_impl_path):
print(f"✅ 找到suw_impl.py: {suw_impl_path}")
print(f"📊 文件大小: {os.path.getsize(suw_impl_path)} 字节")
else:
print(f"❌ 未找到suw_impl.py: {suw_impl_path}")
# 显示Python路径
print(f"🔍 Python路径:")
for i, path in enumerate(sys.path[:5]): # 只显示前5个
print(f" {i+1}. {path}")
except Exception as e:
print(f"❌ 路径设置失败: {e}")
# 步骤4: 模块导入测试
print("\n📝 步骤4: 模块导入测试")
try:
print("🔄 尝试导入suw_impl...")
import suw_impl
print("✅ suw_impl模块导入成功")
print("🔄 尝试导入SUWImpl类...")
from suw_impl import SUWImpl
print("✅ SUWImpl类导入成功")
print("🔄 尝试导入几何类...")
from suw_impl import Point3d, Vector3d, Transformation
print("✅ 几何类导入成功")
except ImportError as e:
print(f"❌ 导入错误: {e}")
print("💡 建议检查:")
print(" 1. 文件路径是否正确")
print(" 2. suw_impl.py是否存在语法错误")
print(" 3. 是否有依赖模块缺失")
except Exception as e:
print(f"❌ 其他导入错误: {e}")
import traceback
traceback.print_exc()
# 步骤5: 实例创建测试
print("\n📝 步骤5: SUWImpl实例创建测试")
try:
if 'SUWImpl' in locals():
print("🔄 创建SUWImpl实例...")
impl = SUWImpl.get_instance()
print(f"✅ 实例创建成功: {type(impl)}")
print("🔄 初始化SUWImpl...")
impl.startup()
print("✅ SUWImpl初始化成功")
# 测试一个简单方法
print("🔄 测试c00命令...")
impl.c00({"uid": "debug_test_001"})
print("✅ c00命令执行成功")
else:
print("⚠️ SUWImpl类未导入跳过实例测试")
except Exception as e:
print(f"❌ 实例创建失败: {e}")
import traceback
traceback.print_exc()
# 步骤6: 几何类测试
print("\n📝 步骤6: 几何类测试")
try:
if 'Point3d' in locals():
print("🔄 测试Point3d...")
p1 = Point3d(1, 2, 3)
p2 = Point3d.parse("4,5,6")
print(f"✅ Point3d测试: {p1}{p2}")
print("🔄 测试Vector3d...")
v1 = Vector3d(1, 0, 0)
v2 = v1.normalize()
print(f"✅ Vector3d测试: {v1}{v2}")
else:
print("⚠️ 几何类未导入,跳过几何测试")
except Exception as e:
print(f"❌ 几何类测试失败: {e}")
import traceback
traceback.print_exc()
# 步骤7: 控制台输出测试
print("\n📝 步骤7: 控制台输出测试")
try:
if BLENDER_AVAILABLE:
# 尝试在Blender中创建一个对象
print("🔄 创建测试立方体...")
bpy.ops.mesh.primitive_cube_add(location=(0, 0, 0))
cube = bpy.context.active_object
cube.name = "DEBUG_TEST_CUBE"
print(f"✅ 测试立方体创建成功: {cube.name}")
# 尝试输出到不同位置
print("🔄 测试不同的输出方式...")
# 标准输出
sys.stdout.write("📤 这是sys.stdout输出\n")
sys.stdout.flush()
# 错误输出
sys.stderr.write("📤 这是sys.stderr输出\n")
sys.stderr.flush()
# Blender报告
try:
bpy.context.window_manager.popup_menu(
lambda self, context: self.layout.label(
text="SUWImpl调试测试运行中..."),
title="调试信息",
icon='INFO'
)
print("✅ Blender弹窗显示成功")
except Exception as popup_e:
print(f"⚠️ Blender弹窗失败: {popup_e}")
else:
print("⚠️ 非Blender环境跳过Blender特定测试")
except Exception as e:
print(f"❌ 控制台输出测试失败: {e}")
# 步骤8: 总结和建议
print("\n" + "=" * 50)
print("📊 调试测试完成!")
print("\n💡 如果你能看到这些输出,说明脚本正在运行")
print("💡 如果看不到输出,可能的原因:")
print(" 1. 输出被重定向了")
print(" 2. Blender控制台没有显示")
print(" 3. 脚本执行方式不对")
print(" 4. 有异常但被静默处理了")
print("\n🔧 建议的调试步骤:")
print(" 1. 在Windows下打开Blender控制台: Window → Toggle System Console")
print(" 2. 检查Blender的Python控制台输出")
print(" 3. 尝试分步执行代码")
print(" 4. 检查Blender的信息面板")
print("\n🎯 下一步测试:")
print(" 如果这个调试脚本运行成功,可以尝试:")
print(" - 运行 quick_start.py")
print(" - 运行 blender_test.py")
print(" - 检查具体的功能实现")
print("\n🎉 调试测试结束!")
# 强制刷新输出缓冲区
sys.stdout.flush()
sys.stderr.flush()