I never done >2 layer PCB’s, nor python scripting in KiCad, but I do now there is a difference between micro via’s and blind / buried via’s. Buried via’s are drilled through the half fabricate, and thus can connect between all layers in that half fabricate, while micro via’s only connect from the active layer to one layer below it. This may explain why:
Therefore I am quite sure that you can do it in a script as well. I have 2000+ via’s to place, so I an quite motivated to find a way to automate the process!
So, my idea at the moment, is to make a simple text substitution in the .kicad_pcb file using a Python script outside KiCAD.
You can indeed set these to arbitrary layers, but from F.Cu to In3.Cu would be nearly impossible to manufacture. But also, as far as I know KiCad does have: PCB Editor / File / Board Setup / Board Stackup / Physical stackup but this does not define layer lamination order, and thus KiCad simply does not know what is doable for the PCB.
And then there is LTCC (Low-temperature Cofired Ceramics) This is a quite special PCB manufacturing technique, can have over 50 layers, and vias can start and stop at arbitrary layers. Enforcing a layer lamination order in KiCad would be senseless for LTCC.
In the end, I agree with you, If you can do it in KiCad’s gui, then you should also be able to script it, but I can’t help with scripting.
Actually I think I have to change it to a blind via F.Cu to In3.Cu, easier to manufacure. Anyway I have to discuss it with the Mfg. Regarding the script it was easy (well quick and dirty, but it worked!). Se below:
fin = open('pxxxx.kicad_pcb', mode='rt', encoding='utf-8')
lines = fin.readlines()
fin.close()
fout = open('pxxxx_mv.kicad_pcb', mode='wt', encoding='utf-8')
for line in lines:
s1 = line.replace('\n','')
if s1.lstrip() =='(via':
fout.write(f'{s1} micro\n')
elif s1.lstrip() == '(layers "F.Cu" "B.Cu")':
fout.write(f"{s1.replace('B.Cu','In3.Cu')}\n")
else:
fout.write(f'{s1}\n')
fout.close()
OK, I have seen the functions, but not yet tried them. Another thing is that I find it difficult to find the arguments to functions e.g. “pcbnew.In1_Cu” etc., were are these documented?
I will try your solution and let you know if it works!
The “API” isn’t really an API, it’s python bindings for some of the internals of KiCad. Some parts of it are documented in the python classes, some parts are very difficult to decipher. You can refer to the KiCad C++ documentation, but it’s difficult, too. I happen to know that many enums are found directly under the pcbnew. You can find more information about the layers in Plugin howtos · Wiki · eelik-kicad / KiCad Documentation · GitLab. I also now found the via types by just experimenting in the KiKad python shell, using the tabulator code completion:
(You found the via types while I was writing, congratulations )
Use “preformatted text” ( </> ) from the forum editor toolbar on a selection. You can see how it adds tickmarks around text.
EDIT: the pcbnew module also includes several useful helper functions. For example, instead of int(dh*mm) you can type the value in mm, for example 0.3 for 0.3 mm drill and use pcbnew.fromMM(): pcbnew.fromMM(0.3). That makes the code easy to write and understand.
Ah, I saw it, but I did not think of it as “code style” !! Now i know! Thank you.
Also I’l have a look at your Gitlab site!
Also the “code completion” was new to me! Nice info, thanks.
I think you are right everything in KiCAD Python is “leaning by doing”.
Nah, actually the Tools → Scripting Console should give completion hints automatically, like in most semi-intelligent coding IDEs, while you’re typing. Tab just completes then.