Files
wheel/scripts/verify_kfl001_plate_v2.FCMacro

28 lines
1.8 KiB
Plaintext

from pathlib import Path
import os,json,traceback
import FreeCAD as A, Part
R=Path(r'C:\projects\wheel'); O=R/'models'/'kfl001_plate_v2'
try:
v1=A.openDocument(str(R/'models'/'kfl001_plate_v1'/'KFL001_plate_V1.FCStd')); a=v1.getObject('Plate_V1').Shape
v2=A.openDocument(str(O/'KFL001_plate_V2.FCStd'));v2.recompute(); f=v2.getObject('Plate_V2'); b=f.Shape
added=b.cut(a).Volume; removed=a.cut(b).Volume
assert added<1e-5 and removed>0
bounds=b.BoundBox
assert abs(bounds.XMin+38)<1e-5 and abs(bounds.XMax-38)<1e-5 and abs(bounds.YMin)<1e-5 and abs(bounds.YMax-75)<1e-5 and abs(bounds.ZMin)<1e-5 and abs(bounds.ZMax-8)<1e-5
# Position checks for both slot end cylinders.
cylinders=[]
for face in b.Faces:
s=face.Surface
if hasattr(s,'Radius') and hasattr(s,'Center'):
cylinders.append((float(s.Radius),float(s.Center.x),float(s.Center.y)))
for x in (-25.5,-21.5,21.5,25.5):assert any(abs(r-2.75)<1e-6 and abs(xx-x)<1e-6 and abs(yy-9)<1e-6 for r,xx,yy in cylinders),cylinders
p=v2.getObject('Parameters'); prev=b.Volume
p.set('B13','1.2 mm');v2.recompute(); changed=f.Shape.Volume
assert f.Shape.isValid() and abs(changed-prev)>1e-3
p.set('B13','1.5 mm');v2.recompute();assert abs(f.Shape.Volume-prev)<1e-4
report={'v2_added_to_v1_mm3':added,'v1_removed_mm3':removed,'bounds_mm':[bounds.XMin,bounds.XMax,bounds.YMin,bounds.YMax,bounds.ZMin,bounds.ZMax],'slot_cylinders_verified':True,'chamfer_parameter_test_1_2mm_volume':changed,'chamfer_parameter_restored':True,'top_edge_to_center_hole_mm':4.5,'top_flat_face_to_center_hole_mm':3.0,'bottom_slot_to_outer_edge_mm':6.25,'bottom_slot_to_flat_face_mm':4.75}
(O/'revision_validation.json').write_text(json.dumps(report,indent=2),encoding='utf-8')
A.closeDocument(v2.Name);A.closeDocument(v1.Name);os._exit(0)
except Exception:
(O/'revision_error.txt').write_text(traceback.format_exc(),encoding='utf-8');os._exit(1)