forked from solderparty/flexypin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_footprints.py
84 lines (61 loc) · 3.29 KB
/
generate_footprints.py
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
74
75
76
77
78
79
80
81
82
83
84
import argparse
import os
def s_expr(indent, *args, **kwargs):
def fix(args):
args = list(args)
for i, arg in enumerate(args):
if type(arg) == float:
args[i] = '{:.2f}'.format(arg)
else:
args[i] = str(arg)
return args
s = ' '.join(fix(args))
args = []
for k, v in kwargs.items():
if type(v) == list:
args.append(s_expr(0, k, ' '.join(fix(v))))
else:
args.append(s_expr(0, k, v))
if args:
s += ' '
s += ' '.join(args)
return indent * ' ' + '(' + s + ')'
def generate(output, pitch, num):
name = 'FlexyPin_1x{:02d}_P{:.2f}mm'.format(num, pitch)
path = '{}/{}.kicad_mod'.format(output, name)
s = s_expr(0, 'module', name, layer='F.Cu')[:-1] + '\n'
# Labels
s += s_expr(2, 'fp_text', 'reference', 'REF**', at=[0, -1.25], layer='F.SilkS', effects=s_expr(0, 'font', size=[1, 1], thickness=0.15)) + '\n'
s += s_expr(2, 'fp_text', 'value', name, at=[0, pitch * (num - 1) + 1.3], layer='F.Fab', effects=s_expr(0, 'font', size=[1, 1], thickness=0.15)) + '\n'
s += '\n'
# Courtyard
s += s_expr(2, 'fp_line', start=[-1.1, pitch * (num - 1) + 0.6], end=[-1.1, -0.6], layer='F.CrtYd', width=0.1) + '\n'
s += s_expr(2, 'fp_line', start=[ 2.7, pitch * (num - 1) + 0.6], end=[-1.1, pitch * (num - 1) + 0.6], layer='F.CrtYd', width=0.1) + '\n'
s += s_expr(2, 'fp_line', start=[ 2.7, -0.6], end=[ 2.7, pitch * (num - 1) + 0.6], layer='F.CrtYd', width=0.1) + '\n'
s += s_expr(2, 'fp_line', start=[-1.1, -0.6], end=[ 2.7, -0.6], layer='F.CrtYd', width=0.1) + '\n'
s += '\n'
# Pads
for i in range(num):
s += s_expr(2, 'pad', i + 1, 'thru_hole', 'rect', at=[0, i * pitch], size=[1.3, 0.90], drill=[0.6, s_expr(0, 'offset', -0.3, 0)], layers=['*.Cu', '*.Mask']) + '\n'
s += s_expr(2, 'pad', '""', 'thru_hole', 'oval', at=[1.55, i * pitch], size=[2.0, 0.95], drill=['oval', 1.7, 0.65], layers=['*.Cu', '*.Mask']) + '\n'
s += s_expr(2, 'model', '${KIPRJMOD}/../3d/flexypin.step', offset=s_expr(0, 'xyz', 0, -i * pitch, 0), scale=s_expr(0, 'xyz', 1, 1, 1), rotate=s_expr(0, 'xyz', 0, 0, 0)) + '\n'
s += '\n'
s += ')'
mod = open(path, 'w')
mod.write(s)
mod.close()
#print(s)
print(path)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Generate FlexyPin footprints', usage='%(prog)s [options]')
parser.add_argument('-o', '--output', type=str, default='./output', help='output path (default: %(default)s)')
parser.add_argument('-p', '--pitch', type=float, default=2.54, help='pin pitch (default: %(default)s)')
parser.add_argument('-n', '--num', type=int, default=1, help='pin number (default: %(default)s)')
parser.add_argument('-r', '--range', help='generate from 1 to [num] instead of just [num]', action='store_true')
args = parser.parse_args()
os.makedirs(args.output, exist_ok=True)
if args.range:
for i in range(1, args.num + 1):
generate(args.output, args.pitch, i)
else:
generate(args.output, args.pitch, args.num)