Created
August 20, 2021 10:39
-
-
Save greyltc/40ec1d061dad3524c187518f40a0bace to your computer and use it in GitHub Desktop.
python holemaker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
"""script that puts holes into pcb""" | |
import pcbnew | |
class HoleMaker(object): | |
"""puts holes into a pcb, units are mm""" | |
board_filename = None | |
pcb = None | |
def __init__(self, board_filename): | |
"""load pcb""" | |
self.board_filename = board_filename | |
self.pcb = pcbnew.LoadBoard(self.board_filename) | |
def npth(self, diameter, x, y): | |
"""put a npth hole in pcb with given diameter and location""" | |
module = pcbnew.FOOTPRINT(self.pcb) | |
npth = pcbnew.PAD(module) | |
npth.SetAttribute(pcbnew.PAD_ATTRIB_NPTH) | |
npth.SetShape(pcbnew.PAD_SHAPE_CIRCLE) | |
npth.SetSize(pcbnew.wxSizeMM(diameter, diameter)) | |
npth.SetDrillShape(pcbnew.PAD_DRILL_SHAPE_CIRCLE) | |
npth.SetDrillSize(pcbnew.wxSizeMM(diameter, diameter)) | |
module.Add(npth) | |
self.pcb.Add(module) | |
loc = pcbnew.wxPointMM(x, y) | |
module.SetPosition(loc) | |
return npth | |
def make_holes(self): | |
"""make the holes""" | |
self.npth(8.1, 0, -17) | |
print("Holes made!") | |
if __name__ == "__main__": | |
board_filename = "board_file_name.kicad_pcb" | |
hm = HoleMaker(board_filename) | |
hm.make_holes() | |
hm.pcb.Save(f"HOLEMOD_{board_filename}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment