def createPrinted(inputboard, outputdir, pcbthickness, thickness, framewidth, ignore, cutout, frameclearance, enlargeholes): """ Create a 3D printed self-registering stencil. """ board = pcbnew.LoadBoard(inputboard) refs = parseReferences(ignore) cutoutComponents = getComponents(board, parseReferences(cutout)) removeComponents(board, refs) Path(outputdir).mkdir(parents=True, exist_ok=True) # We create the stencil based on DXF export. Using it avoids the necessity # to interpret KiCAD PAD shapes which constantly change with newer and newer # versions. height = min(pcbthickness, max(0.5, pcbthickness - 0.3)) bottomPaste, topPaste, outline = pasteDxfExport(board, outputdir) topCutout = extractComponentPolygons(cutoutComponents, "F.CrtYd") bottomCutout = extractComponentPolygons(cutoutComponents, "B.CrtYd") topStencil = printedStencil(outline, topPaste, topCutout, thickness, height, framewidth, frameclearance, enlargeholes, True) bottomStencil = printedStencil(outline, bottomPaste, bottomCutout, thickness, height, framewidth, frameclearance, enlargeholes, False) bottomStencilFile = os.path.join(outputdir, "bottomStencil.scad") solid.scad_render_to_file(bottomStencil, bottomStencilFile, file_header=f'$fa = 0.4; $fs = 0.4;', include_orig_code=True) renderScad(bottomStencilFile, os.path.join(outputdir, "bottomStencil.stl")) topStencilFile = os.path.join(outputdir, "topStencil.scad") solid.scad_render_to_file(topStencil, topStencilFile, file_header=f'$fa = 0.4; $fs = 0.4;', include_orig_code=True) renderScad(topStencilFile, os.path.join(outputdir, "topStencil.stl"))
def create(inputboard, outputdir, jigsize, jigthickness, pcbthickness, registerborder, tolerance, ignore, cutout): board = pcbnew.LoadBoard(inputboard) refs = parseReferences(ignore) removeComponents(board, refs) Path(outputdir).mkdir(parents=True, exist_ok=True) jigsize = (fromMm(jigsize[0]), fromMm(jigsize[1])) addJigFrame(board, jigsize) cutoutComponents(board, getComponents(board, parseReferences(cutout))) stencilFile = os.path.join(outputdir, "stencil.kicad_pcb") board.Save(stencilFile) plotPlan = [ # name, id, comment ("PasteBottom", pcbnew.B_Paste, "Paste Bottom"), ("PasteTop", pcbnew.F_Paste, "Paste top"), ] # get a copy of exportSettingsJlcpcb dictionary and # exclude the Edge.Cuts layer for creation of stencil gerber files exportSettings = exportSettingsJlcpcb.copy() exportSettings["ExcludeEdgeLayer"] = True gerberDir = os.path.join(outputdir, "gerber") gerberImpl(stencilFile, gerberDir, plotPlan, False, exportSettings) gerbers = [os.path.join(gerberDir, x) for x in os.listdir(gerberDir)] subprocess.check_call( ["zip", "-j", os.path.join(outputdir, "gerbers.zip")] + gerbers) jigthickness = fromMm(jigthickness) pcbthickness = fromMm(pcbthickness) outerBorder, innerBorder = fromMm(registerborder[0]), fromMm( registerborder[1]) tolerance = fromMm(tolerance) topRegister = makeTopRegister(board, jigsize, jigthickness, pcbthickness, outerBorder, innerBorder, tolerance) bottomRegister = makeBottomRegister(board, jigsize, jigthickness, pcbthickness, outerBorder, innerBorder, tolerance) topRegisterFile = os.path.join(outputdir, "topRegister.scad") solid.scad_render_to_file(topRegister, topRegisterFile) renderScad(topRegisterFile, os.path.join(outputdir, "topRegister.stl")) bottomRegisterFile = os.path.join(outputdir, "bottomRegister.scad") solid.scad_render_to_file(bottomRegister, bottomRegisterFile) renderScad(bottomRegisterFile, os.path.join(outputdir, "bottomRegister.stl"))
def create(inputboard, outputdir, jigsize, jigthickness, pcbthickness, registerborder, tolerance, ignore, cutout): """ Create stencil and register elements for manual paste dispensing jig. See more details at: https://github.com/yaqwsx/KiKit/blob/master/doc/stencil.md """ board = pcbnew.LoadBoard(inputboard) refs = parseReferences(ignore) removeComponents(board, refs) Path(outputdir).mkdir(parents=True, exist_ok=True) jigsize = (fromMm(jigsize[0]), fromMm(jigsize[1])) addJigFrame(board, jigsize) cutoutComponents(board, getComponents(board, parseReferences(cutout))) stencilFile = os.path.join(outputdir, "stencil.kicad_pcb") board.Save(stencilFile) plotPlan = [ # name, id, comment ("PasteBottom", pcbnew.B_Paste, "Paste Bottom"), ("PasteTop", pcbnew.F_Paste, "Paste top"), ] gerberDir = os.path.join(outputdir, "gerber") gerberImpl(stencilFile, gerberDir, plotPlan, False) gerbers = [os.path.join(gerberDir, x) for x in os.listdir(gerberDir)] subprocess.check_call( ["zip", "-j", os.path.join(outputdir, "gerbers.zip")] + gerbers) jigthickness = fromMm(jigthickness) pcbthickness = fromMm(pcbthickness) outerBorder, innerBorder = fromMm(registerborder[0]), fromMm( registerborder[1]) tolerance = fromMm(tolerance) topRegister = makeTopRegister(board, jigsize, jigthickness, pcbthickness, outerBorder, innerBorder, tolerance) bottomRegister = makeBottomRegister(board, jigsize, jigthickness, pcbthickness, outerBorder, innerBorder, tolerance) topRegisterFile = os.path.join(outputdir, "topRegister.scad") solid.scad_render_to_file(topRegister, topRegisterFile) renderScad(topRegisterFile, os.path.join(outputdir, "topRegister.stl")) bottomRegisterFile = os.path.join(outputdir, "bottomRegister.scad") solid.scad_render_to_file(bottomRegister, bottomRegisterFile) renderScad(bottomRegisterFile, os.path.join(outputdir, "bottomRegister.stl"))