chendy
September 6, 2016, 4:40pm
1
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?
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# Script for KiCad Pcbnew to clone a part of a layout. The scipt clones a row or a matrix
# of similar layouts.
#
# For now, there are no command line parameters given for the script, instead all the settings
# are written in this file. Before using this script, you must have your schema ready.
#
# 1. Use hierarchical sheets for the subschemas to be cloned and annotate them
# so that each sheet has module references starting with a different hundred.
# 2. Import a netlist into Pcbnew and place all the components except the ones to be cloned.
# Also create an optimal layout for the subschema to be used as the template for the clones.
# Surround the layout of the subchema with a zone in the comment layer.
# 3. Save the .kicad_pcb file. Modify SETTINGS at the top of this script to match your board.
# Run this script.
#
# The script has three main parts:
# First, the script moves the modules, which are already imported into the board file. They are
# moved by a predetermined offset amount compared to the template module. (A module with the same
This file has been truncated. show original
Does one have to assign the correct net so it connects up to pads/components correctly?
Thanks
PCB_Wiz
September 6, 2016, 10:33pm
2
This may help - I think this creates a file with the constructed info, that is then added using append.
What are words, right?
Upgrades:
adds 4 segments per turn to the base number
can rotate CW or CCW
[image]
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.
PCB_Wiz
September 6, 2016, 10:47pm
4
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.
PCB_Wiz
September 6, 2016, 11:19pm
6
It may be closer than you think
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
PCB_Wiz
September 6, 2016, 11:26pm
7
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