from pathlib import Path p=Path(__file__).with_name('build_kfl001_plate_v2.py') s=p.read_text(encoding='utf8') s=s.replace('kfl001_plate_v2','kfl001_plate_v3_alt').replace('KFL001_Plate_V2','KFL001_Plate_V3').replace('KFL001_plate_V2','KFL001_plate_V3').replace('Plate_V2','Plate_V3').replace('plate V2','plate V3') s=s.replace("('EdgeChamfer','1.5 mm','Both outer perimeter edges only'),", "('EdgeChamfer','1 mm','Both outer perimeter edges only'),\n ('CornerRadius','3 mm','Rounded upper transitions and lower plan corners'),") old=""" outer=[] for i,e in enumerate(shape.Shape.Edges,1): b=e.BoundBox if abs(b.ZMax-b.ZMin)<1e-7 and (abs(b.ZMin)<1e-7 or abs(b.ZMin-8)<1e-7):outer.append('Edge%d'%i) chamfer=body.newObject('PartDesign::Chamfer','PerimeterChamfer') chamfer.Base=(chamfer.BaseFeature,outer);expr(chamfer,'Size','Parameters.EdgeChamfer')""" new=""" vertical=[] for i,e in enumerate(shape.Shape.Edges,1): b=e.BoundBox if abs((b.ZMax-b.ZMin)-8)<1e-7 and (b.XLength<1e-6 and b.YLength<1e-6): vertical.append('Edge%d'%i) assert len(vertical)==4,vertical fillet=body.newObject('PartDesign::Fillet','OutlineCornerFillets') fillet.Base=(fillet.BaseFeature,vertical);expr(fillet,'Radius','Parameters.CornerRadius') d.recompute() assert not fillet.Shape.isNull() and fillet.Shape.isValid(),fillet.State outer=[] for i,e in enumerate(fillet.Shape.Edges,1): b=e.BoundBox if abs(b.ZMax-b.ZMin)<1e-7 and (abs(b.ZMin)<1e-7 or abs(b.ZMin-8)<1e-7):outer.append('Edge%d'%i) chamfer=body.newObject('PartDesign::Chamfer','PerimeterChamfer') chamfer.Base=(fillet,outer);expr(chamfer,'Size','Parameters.EdgeChamfer')""" assert old in s s=s.replace(old,new) s=s.replace("'perimeter_chamfer':1.5", "'perimeter_chamfer':1.0,'outline_corner_radius':3.0") Path(__file__).with_name('build_kfl001_plate_v3_alt.py').write_text(s,encoding='utf8') Path(__file__).with_name('rebuild_kfl001_plate_v3_alt.FCMacro').write_text("from pathlib import Path\np=Path(__file__).resolve().with_name('build_kfl001_plate_v3_alt.py')\nexec(compile(p.read_text(encoding='utf-8'),str(p),'exec'),{'__name__':'__main__','__file__':str(p)})\n",encoding='utf8')