-
Notifications
You must be signed in to change notification settings - Fork 2
/
kicad2pnp.py
57 lines (47 loc) · 1.47 KB
/
kicad2pnp.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
#!/usb/bin/python3
import sys
import getopt
def usage():
print("Wrong usage!")
def main():
try:
opts, args = getopt.getopt(sys.argv[1:], "ho:i:", ["help", "output=", "input="])
except getopt.GetoptError as err:
# print help information and exit:
print(err) # will print something like "option -a not recognized"
usage()
sys.exit(2)
inp = None
output = None
for o, a in opts:
if o in ('-i', '--input'):
inp = a
elif o in ('-o', '--output'):
ouput = a
else:
usage()
sys.exit(2)
if inp == None:
usage()
sys.exit(2)
if output == None:
output = sys.stdout
else:
output = open(output, "w")
with open(inp, "r") as i:
print(",,,,,,,,,,", file=output)
for line in i:
values = line.strip().split(",")
if len(values) != 7:
continue;
try:
deg = float(values[5])
except:
continue;
if "C" in values[0] or "R" in values[0] or "D" in values[0]:
deg = (deg + 90) % 360
if "Q" in values[0]:
deg = (deg - 90) % 360
print("{},{},{},{},{},{},{},{},{},{},{}".format(values[0], values[2], values[3], values[4], values[3], values[4], values[3], values[4], values[6], deg, values[1]), file=output)
if __name__ == "__main__":
main()