From 190a80f7efc568bb5b442dcb50ab6a4232debd96 Mon Sep 17 00:00:00 2001 From: SZCJW <792430652@qq.com> Date: Sun, 8 Mar 2026 15:22:27 +0800 Subject: [PATCH] x --- scripts/verify_stp.py | 47 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/scripts/verify_stp.py b/scripts/verify_stp.py index 2b90422..5a61731 100644 --- a/scripts/verify_stp.py +++ b/scripts/verify_stp.py @@ -48,21 +48,48 @@ def verify_with_freecad(stp_path): doc = FreeCAD.newDocument("Verification") # 导入STP文件 - FreeCAD 0.21.2 兼容方式 + imported = False + + # 方法1: Import.insert (FreeCAD 0.21+) try: - # 方法1: Import.insert (FreeCAD 0.21+) - Import.insert(stp_path, doc.Name) + Import.insert(stp_path) + imported = True + print("使用 Import.insert 导入成功") except Exception as e1: print(f"Import.insert 失败: {e1}") + + # 方法2: Import.open + if not imported: try: - # 方法2: Import.read - objs = Import.read(stp_path) - if objs: - for obj in objs: - doc.addObject(obj) + Import.open(stp_path) + imported = True + print("使用 Import.open 导入成功") except Exception as e2: - print(f"Import.read 失败: {e2}") - # 方法3: Part.insert (旧版本) - Part.insert(stp_path, doc.Name) + print(f"Import.open 失败: {e2}") + + # 方法3: Part.read + if not imported: + try: + shape = Part.read(stp_path) + if shape and not shape.isNull(): + imported = True + Part.show(shape) + print("使用 Part.read 导入成功") + except Exception as e3: + print(f"Part.read 失败: {e3}") + + # 方法4: Part.insert (旧版本) + if not imported: + try: + Part.insert(stp_path) + imported = True + print("使用 Part.insert 导入成功") + except Exception as e4: + print(f"Part.insert 失败: {e4}") + + if not imported: + print("❌ 所有导入方法都失败") + return None # 获取所有形状对象 shapes = []