x
This commit is contained in:
+37
-10
@@ -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 = []
|
||||
|
||||
Reference in New Issue
Block a user