So far, I’ve covered topics ranging from the basics of rathering netlist data, where are your wires, how to modify layout, zones. Most recently, I added a post on creating simple GUI forms for gathering information needed to do whatever you want your script to do.
I hope you find it helpful. Let me know if there’s something you’d like covered.
Read through everything last night. This is gold!
Very well written, I suspect you also did in-house education?
I think community driven extensions to KiCad is the best idea ever, then you can please everybody.
The core devs can only do so much and the more people can learn to add functionality the better. I hope you enjoy writing these tutorials and continue updating with more posts. I will definitely follow.
Could you please do a for dummies post on how to actually use the scripts inside pcbnew? With pretty pictures of the console when you invoke the scripts and such. There are folks out there that are terrified of python too… like me.
Adding mounting holes. Funny you should mention it. I had the need to do that this week. I haven’t tried to script it yet, but some scripting is needed. Trying to position them in the corners of my boundary is tedious and I probably still didn’t get it right.
I’d be interested to see what you come up with. I’m not familiar with either python or the kicad API (just C++ for AVR - similar but different) and have so far been unable to identify the mechanism to place/import a footprint from a library into pcbnew.
Two possibilities come to mind, both of them have to do with the assumption of certain circuit elements.
First, the script assumes you have a net called clk. In the code, I do a find(’/clk’) without checking if anything is found. The subsequent call to .value() then causes a seg fault for me if clk isn’t there.
Second, the script assume you have a module called U1. In this case, pcbnew doesn’t seg fault, but rather gives a cryptic message.
I’ve added a check for both in the code. Hopefully, that will fix your crash.
To get the full benefit of the demo, you’ll want to change clk and U1 to items you do have.
I started scripting in KiCad 2 weeks ago and had to figure this stuff out all by myself. I also didn’t find the auto-generated API, until I stumbled across it in the manual.
Just one Question:
Did your pcbnew crash when you played around with Vias?
I’ve described that problem in this Post.
Edit: SOLVED it:
I forgot to set the Net.
Made some Quick Tests with Tracks and Vias:
-if Vias got the default NetCode 0, pcbnew crashes when zooming in
-tracks can have the default NetCode 0, without any problems
-if Vias got the default NetCode 0 and you move a component or change Canvas, a function is called, that sets the net to the net of the “connected” track
Is there a way to manipulate kicad’s view with python scripts?
What I want to achieve is:
find component by reference - easy one
ensure it is visible so that I can actually see it in the window
change zoom to such level that I can locate the component on the board (among other component)
I did some search in the internet and read the python API but unfortunately couldn’t find anything appropriate.
Maybe I am to stupid to find it or maybe it doesn’t exist.
I need it to improve kicad assistance in manual pick & place work.
Now the only way is to:
enter components reference and hit enter
and finally zoom out using Alt + F2 as the default zoom after search is way to big ant therefore I can’t locate the component on the board - need to see some other component for sense of direction.
And the whole process must be repeated for each component
The theory its easy, find a common Property of the items you wont to manipulate and search for them. The difficult thing is to find that property. You could use a filter to get your wanted Items out of the modules list. (My first though, the pcbnew.EDA_ITEM.IsSelected Property wont work, as you can’t select multiple items. Maybe another property will work.)
The easiest way, is to pass a list of References of the components you want to modify. Not very smart, but functional.
Another idea (I couldn’t test and look up yet) is, to use the Block Operations and get its Item list.
@DougE Getting the module objects I’d like to group/modify is the part I already know how to do. I got a list of module objects but I cant find any documentation on how to interact with the pcbnew UI. I’d like my script to select a known group of modules, as if I selected those parts using the mouse for block moving/manipulation.
The “Selected” property you mentioned looks like the right approach, but again, nothing I do seems to have any effect on the UI. I tried the “SetSelected()” method which causes “IsSelected()” to return true on multiple objects, but nothing happens in the UI. I can’t move/rotate/manipulate the selected group .