Firstly, I'll try to write this as a FAQ entry as @hermit might use this.
Secondly, when talking about KiCad and scripting it usually means scripting pcbnew as eeschema does not have any support for scripting at the moment. And even with pcbnew, we can distinguish between scripting when pcbnew is running with opened pcb and running bare python scripts to modify pcbnew files directly.
Thirdly, always keep in mind that KiCad users are a heterogeneous group each with its own experiences and cultural background, so when you get advice keep that in mind. I have a 10+ years’ experience in C programing of MCUs mainly in the field of control systems in power electronics and 1+ years of python and I’ve written one KiCad Action plugin. So my python code is quite procedural with light use of object oriented features, list comprehensions and other python features.
So finally some advice on how to start:
The python interface to pcbnew is documented at: KiCAD pcbnew scripting
It documents all the classes and methods available. Keep in mind that this documentation is valid for current nightly release. I do not know where one can get the documentation for the latest stable release (4.0.7). Also the latest stable release (4.0.7) does not support Action plugins, just the basic scripting. I therefore highly recommend nightly releases for scripting development. All the usual warnings apply, when using nightlies.
While you don’t need an IDE for development of scripts I’ve used pyCharm and used python interpreter that comes with python (C:\Program Files\KiCad\bin\python.exe).
If I summarize what you want to do:
1. Find the track selected and get its properties
2. Show relevant data in a pop up window
This is quite a complicated task for someone just starting, but some parts of it are quite easy. If I expand the tasks needed to be done and write the code for it, this should offer you a good start.
Firstly you have to import pcbnew module
Then load the board (I am assuming we are running the script from pcbnew):
board = pcbnew.GetBoard()
Get all the tracks on the board:
tracks = board.GetTracks()
Iterate through all the tracks and find the one which is selected:
selected_track = none
for track in tracks:
selected_track = track
Once we have the track we can print the width of the track:
You can try running this in the pcbnew scripting console. Mind the indents in the for loop.
As for going towards your objective of showing the parameters in a windows, I’d firstly start with KiSelect and (action_menu_move_to_layer) action plugins. You will have to get familiar with wxpython.
My first step would be to write an action plugin, which when run would open a dialog window and show the track in for in the window. Once you have this working you are only one third of way there. You will have to figure how to create a window which is not a dialog so that you can have pcbnew window active (I’d look into Layer View Set for info how to do this) and finally how to pass UI events to action plugin (what you would probably want is to run the search on every click)
Hope this helps
EDIT: I am struggling with multiline code insert