2018-08-04 15:11:45 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
from __future__ import print_function
|
2021-04-27 09:55:56 +00:00
|
|
|
import sys
|
2012-04-06 19:48:00 +00:00
|
|
|
from pcbnew import *
|
|
|
|
|
2021-04-27 09:55:56 +00:00
|
|
|
# A helper function to convert a UTF8 string coming from Kicad for python2 or python3
|
|
|
|
def fromUTF8Text( aText ):
|
|
|
|
if sys.version_info < (3, 0):
|
|
|
|
return aText.encode()
|
|
|
|
else:
|
|
|
|
return aText
|
|
|
|
|
|
|
|
def GenerateBoard():
|
|
|
|
size_0_6mm = wxSizeMM(0.6,0.6)
|
|
|
|
size_1_0mm = wxSizeMM(1.0,1.0)
|
|
|
|
|
|
|
|
# create a blank board
|
|
|
|
pcb = CreateEmptyBoard()
|
|
|
|
|
|
|
|
# create a new footprint, it's parent is our previously created pcb
|
|
|
|
footprint = FOOTPRINT(pcb)
|
|
|
|
footprint.SetReference("M1") # give it a reference name
|
|
|
|
footprint.Reference().SetPos0(wxPointMM(6,-2))
|
|
|
|
footprint.Reference().SetDrawCoord()
|
|
|
|
pcb.Add(footprint) # add it to our pcb
|
|
|
|
m_pos = wxPointMM(50,50)
|
|
|
|
footprint.SetPosition(m_pos)
|
|
|
|
|
|
|
|
# create a pad array and add it to the footprint
|
|
|
|
n = 1
|
|
|
|
for y in range (0,5):
|
|
|
|
for x in range (0,5):
|
|
|
|
pad = PAD(footprint)
|
|
|
|
pad.SetDrillSize(size_0_6mm)
|
|
|
|
pad.SetSize(size_1_0mm)
|
|
|
|
pt = wxPointMM(1.27*x,1.27*y)
|
|
|
|
pad.SetPos0(pt);
|
|
|
|
pad.SetDrawCoord()
|
|
|
|
pad.SetName(str(n))
|
|
|
|
footprint.Add(pad)
|
|
|
|
n+=1
|
|
|
|
|
|
|
|
|
|
|
|
# save the PCB to disk
|
|
|
|
pcb.Save("my2.kicad_pcb")
|
|
|
|
|
|
|
|
def ReadBoard():
|
|
|
|
pcb = LoadBoard("my2.kicad_pcb")
|
|
|
|
|
|
|
|
for m in pcb.GetFootprints():
|
|
|
|
print( 'footprint: ', fromUTF8Text( m.GetReference() ) )
|
|
|
|
|
|
|
|
for p in m.Pads():
|
|
|
|
print('pad ', fromUTF8Text( p.GetName() ), ToMM(p.GetPosition()), ToMM(p.GetOffset()))
|
|
|
|
|
|
|
|
GenerateBoard()
|
|
|
|
ReadBoard()
|