import adsk.core, adsk.fusion, pathlib, math, json, traceback
OUT=pathlib.Path(C28_ROOT)
# Reuse Fusion BRep helpers from the completed build console session.
try:
    o=occurrence('C28_R1_60_');b=worldcopy(o)
    transform=adsk.core.Matrix3D.create();transform.translation=adsk.core.Vector3D.create(0,0,.005)
    tm.transform(b,transform);replace(o,b,'C28_R1_60_Black_Acoustic_Scrim')
    add('C28_R1_62_Scrim_Perimeter_Bond_Film',[rr_ring(44.6,46.6,9.8,42.8,44.8,8.9,-.3,-.25,y=37.5)])
    def p(x,y):return adsk.core.Point3D.create(x/10,y/10,0)
    def outline(s,w,h,r):
        x=w/2;y=h/2;t=math.sqrt(.5)
        points=[((-x+r,-y),(x-r,-y)),((x,-y+r),(x,y-r)),((x-r,y),(-x+r,y)),((-x,y-r),(-x,-y+r))]
        arcs=[((x-r,-y),(x-r+r*t,-y+r-r*t),(x,-y+r)),((x,y-r),(x-r+r*t,y-r+r*t),(x-r,y)),((-x+r,y),(-x+r-r*t,y-r+r*t),(-x,y-r)),((-x,-y+r),(-x+r-r*t,-y+r-r*t),(-x+r,-y))]
        for a,b in points:s.sketchCurves.sketchLines.addByTwoPoints(p(*a),p(*b))
        for a,b,c in arcs:s.sketchCurves.sketchArcs.addByThreePoints(p(*a),p(*b),p(*c))
    shapes=[('Mesh_45x47_R10',[(45,47,10)]),('Scrim_44_8x46_8_R9_9',[(44.8,46.8,9.9)]),('Bezel_Plan_48x50',[(48,50,11.5),(44,46,9.5)]),('Grille_Perimeter_Bond',[(47.8,49.8,11.4),(45.6,47.6,10.3)]),('Mesh_Edge_Bond',[(45,47,10),(44,46,9.5)]),('Scrim_Perimeter_Bond',[(44.6,46.6,9.8),(42.8,44.8,8.9)])]
    for name,profiles in shapes:
        s=root.sketches.add(root.xYConstructionPlane);s.name='C28_R1_CUT_'+name
        for dims in profiles:outline(s,*dims)
        s.saveAsDXF(str(OUT/'drawings'/('C28_R1_'+name+'.dxf')));s.isVisible=False
    cam=app.activeViewport.camera;cam.isSmoothTransition=False;cam.cameraType=adsk.core.CameraTypes.OrthographicCameraType
    cam.eye=pt(-120,35,320);cam.target=pt(0,0,-12);cam.upVector=adsk.core.Vector3D.create(0,1,0);cam.isFitView=False;cam.viewExtents=19
    app.activeViewport.camera=cam;app.activeViewport.refresh()
    (OUT/'audit/details_done.txt').write_text('Scrim retained by separate bond film. Native DXF cutting outlines exported.\n')
    print('Scrim bond and six native DXF cutting outlines added.')
except:
    (OUT/'audit/details_error.txt').write_text(traceback.format_exc());print(traceback.format_exc())
