-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhex_perfboard.py
More file actions
73 lines (56 loc) · 2.42 KB
/
Copy pathhex_perfboard.py
File metadata and controls
73 lines (56 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from circuitpainter import CircuitPainter
from argparse import ArgumentParser
import math
def UntentedVia(painter,x,y,d,w):
painter.layer('F_Cu')
painter.via(x,y,d=d,w=w)
painter.fill()
# By default, vias are tented (covered). Draw circlular openings
# in the soldermask layers to make them untented, instead of
# changing the board-level setting.
painter.layer('F_Mask')
painter.circle(x,y,w/2)
painter.layer('B_Mask')
painter.circle(x,y,w/2)
def HexPerfboard(count,spacing,hole_d,ring_d):
painter = CircuitPainter()
# Make the board shape
painter.layer("Edge_Cuts")
edge_points = []
# Save a list of edge points, in world coordinates
# Note this is a good use case for an absolute points class
for rotation in range(0,361,60):
painter.push_matrix()
painter.rotate(rotation)
edge_points.append(painter._local_to_world((count+1)*spacing,0))
painter.pop_matrix()
for a,b in zip(edge_points[:-1],edge_points[1:]):
painter.line(*painter._world_to_local(*a), *painter._world_to_local(*b))
painter.width(0.05)
painter.fill()
# Center via
UntentedVia(painter,0,0,hole_d,ring_d)
# Draw the hex grid, 1/6th at a time:
for rotation in range(0,360,60):
painter.push_matrix();
painter.rotate(rotation)
painter.translate(spacing,0)
for y in range(0, count):
for x in range(0,count-y):
UntentedVia(painter, x*spacing,0,hole_d,ring_d)
painter.translate(spacing*math.cos(math.radians(60)),-spacing*math.sin(math.radians(60)))
painter.pop_matrix();
return painter
if __name__ == "__main__":
parser = ArgumentParser(description="hexagonal perfboard generator")
parser.add_argument('-c',type=int,default=9, help="Number of hex rings")
parser.add_argument('-s','--spacing',type=float,default=2.54, help="Spacing between the holes (mm)")
parser.add_argument('-d','--hole_diameter',type=float,default=1.02, help="Hole diameter (mm)")
parser.add_argument('-r','--ring_diameter',type=float,default=2, help="Ring diameter (mm)")
parser.add_argument('--save',action="store_true",help="Save the design to a KiCad file")
args = parser.parse_args()
painter = HexPerfboard(args.c, args.spacing, args.hole_diameter,args.ring_diameter)
if args.save:
painter.export_gerber('hex_perfboard')
else:
painter.preview()