From f407703253deeb8b1f43a6da81e050bd40760903 Mon Sep 17 00:00:00 2001 From: SZCJW <792430652@qq.com> Date: Sun, 8 Mar 2026 15:18:41 +0800 Subject: [PATCH] x --- scripts/verify_stp.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/scripts/verify_stp.py b/scripts/verify_stp.py index 9c802ee..2b90422 100644 --- a/scripts/verify_stp.py +++ b/scripts/verify_stp.py @@ -38,6 +38,7 @@ def verify_with_freecad(stp_path): import Part import Mesh import MeshPart + import Import print(f"\n{'='*70}") print(f"FreeCAD 验证") @@ -46,8 +47,22 @@ def verify_with_freecad(stp_path): # 创建新文档 doc = FreeCAD.newDocument("Verification") - # 导入STP文件 - Part.insert(stp_path, "Verification") + # 导入STP文件 - FreeCAD 0.21.2 兼容方式 + try: + # 方法1: Import.insert (FreeCAD 0.21+) + Import.insert(stp_path, doc.Name) + except Exception as e1: + print(f"Import.insert 失败: {e1}") + try: + # 方法2: Import.read + objs = Import.read(stp_path) + if objs: + for obj in objs: + doc.addObject(obj) + except Exception as e2: + print(f"Import.read 失败: {e2}") + # 方法3: Part.insert (旧版本) + Part.insert(stp_path, doc.Name) # 获取所有形状对象 shapes = []