Kicad board layout question

Oh, that is a genius idea! I was trying to work out how you could use the structure of the schematic to help lay things out, but just using the positions from the schematic is brilliant!

I guess it has trouble with hierarchical sheets? I don’t know what would be the best way to deal with those.

For that, you’d likely need to know Python better than I do? Then again - this works on a very simple basis. It only looks up the Unique identifiers + positions in one text file, matches them with the PCB file, looks a few positions backward in the PCB file to find the position (may vary a little) and then overwrites the PCB position line. I really love that Kicad is all text. Makes stuff like this much easier!

But - I don’t have any good schematic files with multiple sheets available (I prefer just making my schematic bigger). Maybe some of you could test this on multi-sheet files?

I think that simple approach is close to perfect. I can think of a very quick and dirty way to make it work for hierarchical schematics. I’ll have a go at doing it this weekend.

1 Like

I wonder if the ideal KiCAD integration might be an option somewhere in the netlist importer (or just a menu option somewhere, since it’s rarely used) to take default positions from the schematic like that.

For subsheets - I suspect it doesn’t matter where exactly they get placed, once the subsheet components themselves are all grouped together-ish?

Really love this logical grouping - I spend so damn long reproducing something like this before I can really consider the physical layout, it’s a necessary, time wasting step, particularly for things like decoupling cap close to the correct pins etc. Nice work!

Right. I think for sub-sheets, all that’s needed is to make sure each sub-sheet (and the main sheet) have their components placed in non-overlapping regions. You’re going to move everything around right away anyway, so it doesn’t matter too much exactly where things are at that high-level, so long as there is some logical grouping (which you can control by how you lay components out in the schematic).

@jensa This looks great! So far I have tended to manually cross-highlight the schematic to group circuits for layout.

This is a great starting point which should speed things up. Out of curiosity, what happens if you use it on a hierarchical sheet?

It doesn’t work for hierarchical sheets yet, as far as I can tell. I’m going to try to do something for that tomorrow.

2 Likes

I made a few changes to Jens’s script to make it work as a KiCad plugin and to make it work with hierarchical sheets. If you take the script from https://github.com/ian-ross/KiCad-parts/blob/placement-plugin/plugins/SchematicPositionsToLayout.py and copy it into your ~/.kicad_plugins directory, you should be able to use it as an entry in the “Tools -> External Plugins…” menu item in pcbnew.

The plugin just rearranges all the components in the layout to match the way they’re arranged in the schematic without doing anything to the layout file. It happens as a normal editing action, so you can do it, take a look, and undo it if you don’t like what you see. If you do like what you see, you can save the layout and continue editing.

(The way that hierarchical sheets are handled is rough: each sheet is just laid out in order down the page, ensuring no overlaps. Given what this thing is intended to be used for – the very first organisation of components when you first import a new netlist – that seems like a reasonable way to go.)

3 Likes

@jensa I think it’s a fantastic idea, can’t believe the scornful response it got on the KiCad forum :frowning:

@ian thanks for taking it up a level, this is one plugin I will definitely install!

I don’t know why, but I went to have a look at the KiCad forum discussion about it. It made me sigh. Certainly doesn’t inspire me to join the forums there…

Unfortunately it does not show up for me in Tools->External Plugins. I copied the script text from the repo, saved it to a text file with ‘.py’ as its extension, and put it in my scripts folder. I know (I think) that I’ve put it in the right place because it’s in the same directory as HTMLBOMGenerator, which does appear in the External Plugins menu.

Does pressing “Refresh plugins” under the Tools menu make any difference? And what version of KiCad do you have? I’ve only tested it with 5.1.6, and I’ve only started using KiCad quite recently, so I’m not at all familiar with differences with earlier versions.

Refreshing doesn’t help, nor does quitting out and relaunching KiCad. I’m running 5.1.6 under MacOS right now; will give it a shot under Windows when I have a chance.

Huh. Weird. I don’t know why it wouldn’t be working. One other thing to say is that I’ve only tested it on Linux, but I would have expected plugins to work the same on different platforms, as long as you put the plugin script in the right directory. Let me just check that what I’ve put on GitHub is right…

Oh, dammit, I think I know what it is. The script is Python 3, and I remember hearing something the other day about KiCad being locked on Python 2 for Windows and MacOS until version 6.

Let me have a look at some other plugins and see how they deal with the Python 3 vs. Pyhon 2 issue. I’ll let you know when it’s fixed.

In the meantime, this thing only works on KiCad 5.1.6 on Linux. (On the summer solstice in a leap year…)

1 Like

Very slick fix, @jensa. I’ll give it a try soon!

Wow, awesome plugin! It drives me nuts finding all the bits and moving them around before I can start routing. Especially when there are 100 x 100 nF caps next to each other all connected to 5 different power domains!

@JuliaTruchsess I believe that I’ve got it working on Windows now. (At least, I’ve tested it in a Windows 10 VM and it works there.) It was this Python 3 (Linux) vs. Python 2 (Windows and MacOS) thing.

The modified version is here: https://github.com/ian-ross/KiCad-parts/blob/placement-plugin/plugins/SchematicPositionsToLayout.py

1 Like

Works now under MacOS High Sierra, thanks!

Great! Thanks for testing it!