Python scripting tracks / vias in PcbNew?

I want to python script some tracks and vias. But how?

There was this layout_cloner.py posted by somebody here, which shows how to clone tracks but how to create?

Does one have to assign the correct net so it connects up to pads/components correctly?

Thanks

This may help - I think this creates a file with the constructed info, that is then added using append.

Yes, look at a kicad_pcb file and each track segment has a net-number, that is derived from the net-name table.
Without that, the DRC does not connect things properly.

It’s not quite as elaborate - one needs to manually edit the pcb_kicad file and add the content of the script to it.
Sorry.
:pensive:

Hehe oops, I skim read too quickly, and assumed that was what ‘manual’ meant.

That said, it should not be too hard to have it append-able ?
I’ve found append is quite tolerant, and good for easy merge of pieces.

Main linking-variable here seems the Net number, and if the user specifies that (or maybe the script finds it, in a loaded-design, given a name ?) then a block of tracks should append ok ?
See below, it is even easier than I thought - turns out Net Number is loosely used, the Net Name is enough to connect.

The script only creates the bare track info, not a kicad_pcb file.
KiCAD can’t work with it out of the box.

It may be closer than you think :slight_smile:
I just did a rough/quick test , and I find the Net Number is quite tolerant, and not strict.
The net name seems to be the pivot.

eg I take a parts-only design, then import a NET file, and it contains
(net 51 $$$22774)

then I take a Track only file, edited to be this

(net 660 $$$22774) ... (segment (start 25.4 -22.86) (end 25.4 -24.942292) (width 0.2032) (layer F.Cu) (net 660)) (segment (start 25.4 -24.942292) (end 25.0825 -25.259792) (width 0.2032) (layer F.Cu) (net 660)) (segment (start 25.0825 -25.259792) (end 25.0825 -33.83407) (width 0.2032) (layer F.Cu) (net 660)) (segment (start 25.0825 -33.83407) (end 22.66823 -36.24834) (width 0.2032) (layer F.Cu) (net 660)) (segment (start 22.66823 -36.24834) (end 22.55266 -36.24834) (width 0.2032) (layer F.Cu) (net 660)) (segment (start 22.55266 -36.24834) (end 21.59 -37.211) (width 0.2032) (layer F.Cu) (net 660)) (segment (start 21.59 -37.211) (end 21.59 -37.846) (width 0.2032) (layer F.Cu) (net 660)) (segment (start 25.4 -22.86) (end 26.529694 -22.86) (width 0.2032) (layer B.Cu) (net 660)) (segment (start 26.529694 -22.86) (end 26.783694 -22.606) (width 0.2032) (layer B.Cu) (net 660)) (segment (start 26.783694 -22.606) (end 28.9226546666667 -22.606) (width 0.2032) (layer B.Cu) (net 660)) (segment (start 28.9226546666667 -22.606) (end 29.3036546666667 -22.987) (width 0.2032) (layer B.Cu) (net 660)) (segment (start 29.3036546666667 -22.987) (end 38.862 -22.987) (width 0.2032) (layer B.Cu) (net 660)) (segment (start 47.625 -17.526) (end 44.323 -17.526) (width 0.2032) (layer F.Cu) (net 660)) (segment (start 44.323 -17.526) (end 38.862 -22.987) (width 0.2032) (layer F.Cu) (net 660)) (via (at 38.862 -22.987) (size 0.889) (drill 0.508) (layers F.Cu B.Cu) (net 660)) (via (at 25.4 -22.86) (size 0.889) (drill 0.508) (layers F.Cu B.Cu) (net 660))
and append that, and voila, the traces above connect to the pads.
This in spite of one saying 660 and the other 51.

That means you can probably assign any dummy net-number, and valid netname, and it should append ok.

Yes, attached file appends ok, to an existing design with a valid $$$22774 net name.Preview_2_KiCad_n660.kicad_pcb (1.7 KB)

2 Likes

The above slight diversion, gives an example of a short file with tracks and vias, ( that could be python-created), that will File.AppendBoard load onto an existing design, and connect as expected. Just needs the NetName ==.

2 Likes