Files
Scanning the repository...
Last update 2 years 1 month
by Andrea Toninelli
panelizeBoard005032.py''' panelizeBoard.py This script uses KiKit to create a panel of KiCAD pcbnew boards, following certain specific rules It's a very specific example, thus likely not ready for any other uses. However I think it can be a starting point for doing your own script usage: python3 panelizeBoard.py <boardfile.kicad_pcb> <panelfile.kicad_pcb> Note: if using windows, you can only run kikit in WSL. Refer to the documentation ''' __author__ = "Andrea Toninelli" __copyright__ = "Do whatever you like with this file, as long as you don't consider me responsible for anything :)" from kikit import panelize #import pcbnew from pcbnewTransition import pcbnew import sys from shapely import Polygon #added 20230628 ####################### CONSTANTS AND VARIABLES #################################################### # 005032 v6: 42mm x 26mm #board dimensions altezzaScheda = 26 # board height lunghezzaScheda = 42 # board length tolleranza = 5 # coordinates of panel origin # NOTE: in pcbnew, Y increases going DOWN panelOriginX = 15 panelOriginY = 19 panelOrigin = pcbnew.wxPointMM(panelOriginX, panelOriginY) # panel configuration righe = 4 #rows colonne = 5 #columns spazioOrizzontale = 8 # horizontal space between boards spazioVerticale = 0 # vertical space between boards diametroFresa = 2 # milling tool diameter spessoreBinari = 6 # rails thickness spessoreBinarioCentrale = 10 rigaPrecedenteBinarioCentrale = 1 # il binario lo metto dopo la seconda riga, che ha indice 1 # in my case, i had to create a "high tab" and "low tab" # in order to leave space for the WiFi module antenna # those tabs then "merge" in the junction area of the boards spessoreTabAlta = 4.5 #high tab thickness spessoreTabBassa = 1.5 #low tab thickness offsetVerticaleTabBassa = altezzaScheda - spessoreTabBassa #vertical offset of low tab listaVCutsOrizzontali = [] # list of Y coordinates of horizontal Vcuts listaVCutsVerticali = [] # list of X coordinates of vertical Vcuts listaTabs = [] #list of tabs (shapely.Polygon objects) ## 20230623 for kikit v1.3, change tabs type from wxRect to shapely.Polygon ##################################################################################################### #initialize the panel variable panel = panelize.Panel(sys.argv[2]) for c in range(colonne): # for every column for r in range(righe): # for every row #calculate board origin coordinates offsets from panelOrigin #NOTE: origin is top left corner origineSchedaX = c*(lunghezzaScheda+spazioOrizzontale) origineSchedaY = r*(altezzaScheda+spazioVerticale) if (r>rigaPrecedenteBinarioCentrale): #nelle ultime 2 righe aggiungo l'offset dovuto al binario centrale origineSchedaY = origineSchedaY + spessoreBinarioCentrale #append the board posizione = panel.appendBoard(sys.argv[1], \ panelOrigin + pcbnew.wxPointMM(origineSchedaX, origineSchedaY), \ origin=panelize.Origin.TopLeft, \ tolerance=panelize.fromMm(tolleranza)) #in the last column, I add the horizontal Vcuts if (c==colonne-1): listaVCutsOrizzontali.append(panelOriginY + origineSchedaY) #board upper Vcut #since the vertical space between boards is 0, the board's lower Vcut is needed only in the last row + the row below the central rail if (r==righe-1) | (r==rigaPrecedenteBinarioCentrale): listaVCutsOrizzontali.append(panelOriginY + origineSchedaY + altezzaScheda) #in the last row, I add the vertical Vcuts if (r==righe-1): if (c < colonne - 1): #board rightmost Vcut (not needed in the last column) listaVCutsVerticali.append(panelOriginX + origineSchedaX + lunghezzaScheda) if (c > 0): #board leftmost Vcut (not needed in the first column) listaVCutsVerticali.append(panelOriginX + origineSchedaX) #tab creation if (c > 0): # since tabs are created on the left side of the boards, they are not needed in the first colum #higher tab coordTL=(panelize.fromMm(panelOriginX + origineSchedaX - spazioOrizzontale), panelize.fromMm(panelOriginY + origineSchedaY)) coordTR=(panelize.fromMm(panelOriginX + origineSchedaX), panelize.fromMm(panelOriginY + origineSchedaY)) coordBR=(panelize.fromMm(panelOriginX + origineSchedaX), panelize.fromMm(panelOriginY + origineSchedaY + spessoreTabAlta)) coordBL=(panelize.fromMm(panelOriginX + origineSchedaX - spazioOrizzontale), panelize.fromMm(panelOriginY + origineSchedaY + spessoreTabAlta)) #tabAlta = pcbnew.wxRectMM(panelOriginX + origineSchedaX - spazioOrizzontale, \ # panelOriginY + origineSchedaY, \ # spazioOrizzontale, \ # spessoreTabAlta) tabAlta = Polygon((coordTL, coordTR, coordBR, coordBL)) listaTabs.append(tabAlta) #lower tab coordTL=(panelize.fromMm(panelOriginX + origineSchedaX - spazioOrizzontale), panelize.fromMm(panelOriginY + origineSchedaY + offsetVerticaleTabBassa)) coordTR=(panelize.fromMm(panelOriginX + origineSchedaX), panelize.fromMm(panelOriginY + origineSchedaY + offsetVerticaleTabBassa)) coordBR=(panelize.fromMm(panelOriginX + origineSchedaX), panelize.fromMm(panelOriginY + origineSchedaY + offsetVerticaleTabBassa + spessoreTabBassa)) coordBL=(panelize.fromMm(panelOriginX + origineSchedaX - spazioOrizzontale), panelize.fromMm(panelOriginY + origineSchedaY + offsetVerticaleTabBassa + spessoreTabBassa)) #tabBassa = pcbnew.wxRectMM(panelOriginX + origineSchedaX - spazioOrizzontale, \ # panelOriginY + origineSchedaY + offsetVerticaleTabBassa, \ # spazioOrizzontale, \ # spessoreTabBassa) tabBassa = Polygon((coordTL, coordTR, coordBR, coordBL)) listaTabs.append(tabBassa) #central rail creation if (r==rigaPrecedenteBinarioCentrale): if (c==colonne-1): # l'ultima colonna rimuovo la lunghezza in eccesso riduzioneFinale=spazioOrizzontale else: riduzioneFinale=0 coordTL=(panelize.fromMm(panelOriginX + origineSchedaX), panelize.fromMm(panelOriginY + origineSchedaY + altezzaScheda)) coordTR=(panelize.fromMm(panelOriginX + origineSchedaX + lunghezzaScheda + spazioOrizzontale - riduzioneFinale), panelize.fromMm(panelOriginY + origineSchedaY + altezzaScheda)) coordBR=(panelize.fromMm(panelOriginX + origineSchedaX + lunghezzaScheda + spazioOrizzontale - riduzioneFinale), panelize.fromMm(panelOriginY + origineSchedaY + altezzaScheda + spessoreBinarioCentrale)) coordBL=(panelize.fromMm(panelOriginX + origineSchedaX), panelize.fromMm(panelOriginY + origineSchedaY + altezzaScheda + spessoreBinarioCentrale)) #binarioCentrale = pcbnew.wxRectMM(panelOriginX + origineSchedaX, \ # panelOriginY + origineSchedaY + altezzaScheda, \ # lunghezzaScheda + spazioOrizzontale - riduzioneFinale, \ # spessoreBinarioCentrale) binarioCentrale = Polygon((coordTL, coordTR, coordBR, coordBL)) listaTabs.append(binarioCentrale) # tabs are appended to the panel for t in listaTabs: panel.appendSubstrate(t) # top and bottom rails are added panel.makeRailsTb(panelize.fromMm(spessoreBinari)) # milling profile is added # this also merges the areas where the mill cannot fit # (in my case, high tab and low tab) panel.addMillFillets(panelize.fromMm(diametroFresa/2)) #copperfill is added panel.copperFillNonBoardAreas(clearance=panelize.fromMm(0)) #vertical vcuts are added for x in listaVCutsVerticali: panel.addVCutV(panelize.fromMm(x)) #horizontal vcuts are added for y in listaVCutsOrizzontali: panel.addVCutH(panelize.fromMm(y)) #finally the panel is saved panel.save()