I have a project where I want to do everything in python. I am using SKiDL. I want to import it’s output (.net file) into pcbnew using a script.
In other words, I am looking to run the load Netlist function using python.
I have a project where I want to do everything in python. I am using SKiDL. I want to import it’s output (.net file) into pcbnew using a script.
In other words, I am looking to run the load Netlist function using python.
You could create an empty board and then replace its netlist like this:
import pcbnew
brd = pcbnew.BOARD()
brd.ReplaceNetlist(some_netlist)
Unfortunately, I can’t find anything in the PCBNEW API that lets you create a netlist object by reading a netlist file. Maybe someone else knows how to do that.
There is no such method in current API, where did you get that from?
@ScottHilton to create netlist manually you will have to create instances of pcbnew.NETINFO_ITEM
for each net and add them using board.Add(net_info)
. Then set each pad/track/whatever’s net as desired using item.SetNet(net_info)
.
Open the Python shell in PCBNEW 5.1.4. Then do this:
import pcbnew
brd = pcbnew.BOARD()
dir(brd)
You will see the function ReplaceNetlist() in the list. Try it. It actually takes less time than writing a post saying it doesn’t exist.
I checked current API docs, checked my nightly build and also searched ReplaceNetlist
in source repo, all returned no matches.
It appears it existed in 5.1 but was removed later.
My guess is that it was never usable in the first place because NETLIST class was not available but I can’t easily check it right now since I don’t have access to 5.1 on this machine and I’m too lazy to build it.
Either way, even if it works in 5.1 I wouldn’t rely on it.
Edit: just checked in 5.1, no NETLIST in api so you can’t use that method.
I found https://xesscorp.github.io/kinparse/docs/_build/singlehtml/index.html
I think it might be useful for my problem but I’m not sure.
I’ll have the script for going from a KiCad netlist to the .kicad_pcb file this afternoon. (Yes, kinparse is part of it.)
The utility to convert a KiCad netlist into a .kicad_pcb file is here.
It places all the components on top of each other at (0,0). I’m not sure if that’s what you want since I don’t know what you’re doing with this.
Wow that looks great.
I can’t get it to load the libraries and footprints properly. It assumes certain library syntax that isn’t always the same. That said it is really close and I am looking for fixes.
This is nifty, as is opens up scope for Library translation tables, (BOM aliasing) and can probably give better error messages than the inbuilt Load Netlist.
I glanced at the code, but not run it yet - couple of questions :
a) Can it report the import stats, like parts added, nets added, fields added ?
b) Can it tolerate being run multiple times, in a net-merge manner ?
ie it should check/report if a part already exists, but add new parts.
Net conflicts get trickier, as users may have split or renamed a few nets, but a check-before-add step can issue warnings until the user ‘clears the table’ in the PCB side
I actually have a mirror-image python script, that does PcbNew_Export_PcbNew_NET.py, or
it would be called pcb2kinet.py using your naming convention.
I wrote it to allow use in Non KiCAD or Non schematic workflows, and to allow version control by netlist compares.
Compare of a fully routed PCB file, can generate a lot of error chaff, but compare of netlists gives a more manageable difference list, plus a round-trip system is useful for testing anyway…
Scott, have you looked at my reply to your Github issue on this?
It doesn’t now, but these stats would be easy to report.
It was built as a “one and done” application without regard to merging parts and nets into an existing, non-empty board. Obviously that could be done but it requires addressing the points you raise.
Have you registered this script on the list of third-party tools? (That’s a rhetorical question: nobody does. That’s why we have 457 different BOM extraction tools.)
This is the way to go instead of graphical compares of schematic images.
I see I have posted a copy of PcbNew_Export_PcbNew_NET.py already in another thread.
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.