from pathlib import Path import FreeCAD as A, Part, json, os p=Path(r'C:\projects\wheel\models\symmetric_corner_18_concept') d=A.openDocument(str(p/'Assembly_对称角码装配_概念.FCStd')); d.recompute() results=[] for o in d.Objects: if not o.Name.startswith(('NewMotorCorner','NewMotorBase','NewSwitchBase','NewBeamBase')): continue shape=o.Shape; bb=shape.BoundBox; holes=[] for f in shape.Faces: s=f.Surface if not hasattr(s,'Radius') or abs(s.Radius-2.5)>1e-5: continue ax=s.Axis; c=s.Center if o.Name.startswith('NewMotorCorner'): coord='x' if abs(ax.z)>.9 else 'z' elif o.Name.startswith(('NewMotorBase','NewSwitchBase')): coord='y' if abs(ax.z)>.9 else 'z' else: coord='x' if abs(ax.z)>.9 else 'z' val=getattr(c,coord); vmin=getattr(bb,coord.upper()+'Min'); vmax=getattr(bb,coord.upper()+'Max') holes.append({'axis':[round(ax.x,3),round(ax.y,3),round(ax.z,3)],'end_distance':round(min(abs(val-vmin),abs(vmax-val)),5),'coord':coord}) results.append({'name':o.Name,'holes':holes}) assert len(results)==12, len(results) for item in results: assert len(item['holes'])==2, item assert all(abs(h['end_distance']-8)<0.001 for h in item['holes']),item (p/'对称孔位验证.json').write_text(json.dumps(results,ensure_ascii=False,indent=2),encoding='utf8') A.closeDocument(d.Name);os._exit(0)