$src = Get-Content -Raw -Encoding UTF8 'C:\projects\wheel\scripts\build_kfl_same_flange_125.py' $pairs = @( @("O=R/'models'/('kfl_same_flange_%d'%shaftlen)", "O=R/'models'/'kfl_125_switch60_concept'"), @("-108 if n=='Shaft' else -112", "-108 if n=='Shaft' else -118"), @("-50.5-shaftlen", "-56.5-shaftlen"), @("4,-119", "4,-125"), @("20,20,190,V(x-10,-75,-170)", "20,20,200,V(x-10,-75,-180)"), @("[-84,-150]", "[-84,-162]"), @("(-150,-153,-1)", "(-162,-165,-1)"), @("cy(15,20,0,0,-176).cut(cy(6.2,20.02,0,0,-176.01))", "cy(15,20,0,0,-188).cut(cy(6.2,20.02,0,0,-188.01))"), @("cy(28.5,4,0,0,-180).cut(cy(6.2,4.02,0,0,-180.01))", "cy(28.5,4,0,0,-192).cut(cy(6.2,4.02,0,0,-192.01))"), @("24*math.sin(a),-180.01", "24*math.sin(a),-192.01"), @("wheel70.translate(V(0,0,-180))", "wheel70.translate(V(0,0,-192))"), @("Part.makeBox(110,80,50,V(-55,-40,-138.5)).cut(cy(23.5,50.02,0,0,-138.51))", "Part.makeBox(110,80,60,V(-55,-40,-149.5)).cut(cy(23.5,60.02,0,0,-149.51))"), @("'50mm switch bounding placeholder; 47mm bore ASSUMED'", "'60mm switch and wiring clearance envelope; 47mm bore ASSUMED'"), @("24*math.sin(a),-188)", "24*math.sin(a),-200)"), @("min(-156,-50.5)-max(-176,z_end)", "min(-168,-56.5)-max(-188,z_end)"), @("min(-176,-50.5)-max(-180,z_end)", "min(-188,-56.5)-max(-192,z_end)"), @("'Shaft nominal 12 x %d; z=%.1f..-50.5; motor hub z=-70..-50; motor insertion 19.5mm assumed and axial gap to base 0.5mm.'", "'Shaft nominal 12 x %d; z=%.1f..-56.5; motor hub z=-70..-50; motor insertion 13.5mm assumed and axial gap to base 6.5mm.'"), @("'Wheel hub z=-176..-156, front plate z=-180..-176;", "'Wheel hub z=-188..-168, front plate z=-192..-188;"), @("'Bearing positions, 50mm switch envelope and cam as previous shifted design;", "'Rear bearing retained; front bearing shifted 12mm to wheel; switch 60mm with 1mm nominal gap on each side, cam shifted 6mm;"), @("'KFL approximate 48 bolt pitch and 14.5 inner width, housing/protrusion guessed; 8mm plate 30.2 hole guessed; no real module shape, its 47mm hole is an assumption.'", "'KFL approximate 48 bolt pitch and 14.5 inner width, housing/protrusion guessed; 8mm plate 30.2 hole guessed; 60mm switch/wire envelope placeholder, its 47mm hole is an assumption.'"), @("KFL125_Schematic", "KFL125_Switch60_Schematic") ) foreach ($pair in $pairs) { if (-not $src.Contains($pair[0])) { throw "Cannot find required source fragment: $($pair[0])" } $src = $src.Replace($pair[0], $pair[1]) } $extraPairs = @' pairs += [('SwitchEnvelope','Plate0',sw,plates[0].Shape),('SwitchEnvelope','Plate1',sw,plates[1].Shape)] pairs += [('SwitchEnvelope','KFLHousing0',sw,bearings[0].Shape),('SwitchEnvelope','KFLHousing1',sw,bearings[2].Shape)] pairs += [('Key','Shaft',cam['Key'],cam['Shaft']),('Key','CamUpper',cam['Key'],cam['Upper']),('Key','CamLower',cam['Key'],cam['Lower'])] pairs += [('CamUpper','Shaft',cam['Upper'],cam['Shaft']),('CamLower','Shaft',cam['Lower'],cam['Shaft'])] pairs += [('CamUpper','RearKFL',cam['Upper'],bearings[0].Shape),('CamUpper','FrontKFL',cam['Upper'],bearings[2].Shape)] pairs += [('CamLower','RearKFL',cam['Lower'],bearings[0].Shape),('CamLower','FrontKFL',cam['Lower'],bearings[2].Shape)] pairs += [('Shaft','Wheel70',cam['Shaft'],wheel70),('WheelHub','SwitchEnvelope',wh,sw),('MotorFlange','SwitchEnvelope',flange,sw)] for a,b,sa,sb in pairs: '@ if (-not $src.Contains(' for a,b,sa,sb in pairs:')) { throw 'Cannot extend collision checks' } $src = $src.Replace(' for a,b,sa,sb in pairs:', $extraPairs) [System.IO.File]::WriteAllText('C:\projects\wheel\scripts\build_kfl_125_switch60.py', $src, [System.Text.UTF8Encoding]::new($false)) $macro = @' from pathlib import Path script=Path(r'C:\projects\wheel\scripts\build_kfl_125_switch60.py') exec(compile(script.read_text(encoding='utf8'),str(script),'exec'),{'__name__':'__main__','__file__':str(script)}) '@ [System.IO.File]::WriteAllText('C:\projects\wheel\scripts\rebuild_kfl_125_switch60.FCMacro', $macro, [System.Text.UTF8Encoding]::new($false))