KiCAD export from command line

What I am trying to do:

in short:

.kicad_pcb > .dsn > .gbr 
(kicad pcb > Specctra > Gerber) 
.kicad_pcb > .dsn > .kicad_pcb
(kicad pcb > Specctra > kicad pcb)

inside (Linux) terminal

in long:

I want to automate a task in KiCAD that I have to do repeatedly.
To do this I wanted to write a bash script in the (Linux) terminal that can do these steps.
It shoulf basically take a .kicad_pcb file generated by different software and parse it to an autorouter (I’m using freerouting from GitHub) and then convert it into a Gerber file for manufacturing. Turning it back into a .kicad_pcb file would be fine as well.

What I have tried so far:

There is an option in KiCAD: File > Export > Specctra DSN
This works perfectly fine but can’t be automated.
I tried to find Macros (key combinations) but couldn’t find any.

Afterwards I looked for a conversion software, but there doesn’t seem to be any software that converts from .kicad_pcb to .dsn. Not even with steps in between like: .kicad_pcb > .brd > .dsn.

Then I found out about python-scripts inside of KiCAD but it seems as if you can only start those from inside KiCAD manually.

The next idea was to look into the source code of KiCAD. One thing I found was the function:
bool ExportSpecctraFile( const wxString& aFullFilename );
But I have no idea how I could execute these functions from anywhere. Maybe someone can give me a hint.
A different idea was to copy the source code inside KiCAD that converts these files inside of KiCAD and use them externally, but I have no idea where to find these.
I have done very little C/C++ coding and would try if there is a way to do these things I am trying to accomplish but don’t know where to start as there seems to be little documentation. How hard would It be?

One last thing I found was KiBot, a repository on GitHub that does some of the things I am asking for, but doesn’t include the option to export a .dsn file. Other similar repositories lack this function as well.

Is there any way to accomplish what I am trying to do? The way it could work is not important to me as long as it’s executable from a local command line.

Thanks in advance!


P.S.: Sorry if I posted in the wrong category or didn’t follow any guidelines. I am new here and don’t quite know yet how to ask.

What KiCad version are you using?
I’ve seen several mentions and proposals for CLI improvements on gitlab, but I do not follow this topic closely.

Thanks for your reply!
I’m using version 5.1.9.
I have looked up the kicad-cli. There are some options but not for exporting .dsn files. But maybe I’m missing something.

You can automate gerbers export using KiBot GitHub - INTI-CMNB/KiBot: KiCad automation utility

But you’re out of luck with specctra files. Maybe if you ask for a feature in KiBot github they can add an export but not sure about import.

Yeah, that’s at least something. I will make a request. It does seem weird to me that such a feature is not more requested as it would be a useful thing for everyone that uses an autorouter.

You are skimping over a big piece of the ugly truth.
From your post it looks like you want an automated output to an autorouter from KiCad, then directly create gerber files and order your PCB’s.

That is a method that is not going to work with the low quality of available autorouters. An autorouter can be a useful tool, but a lot of experienced PCB designers do not use autorouters at all because of the low quality of the PCB layout they generate, and cleanup of the mess can easily be more work then laying the tracks manually in the first place. That is one of the reasons autorouters are not high on the priority list for KiCad. There is also a lot more to routing a PCB then making connections. There are decoupling capacitors with critical wiring demands, length matching, wide high current tracks, GND plane for EMC control, support near connectors to prevent PCB’s from bending during connector insertion so brittle SMD parts don’t break and many more factors.

You are on old kicad version. V6 has an easy to install and use freerouting plugin that allows you to run autorouter on your board and import back results in one click.

@paulvdh Thank you for the link. You are absolutely right you seem a lot more knowledgeable than me in this regard. I actually hoped that it would be sufficient for my use case, as I only have to connect a few controller pins with some components with equal-sized tracks, nothing too complex in my opinion. I have not yet tried if the boards I designed with the autorouter are working as I expect. What I did was look at the results, and they seemed okay to me. Not pretty for sure but functional as far as I can tell.
I should probably look into that first and test a bit to see if it’s at least reliable to some degree.

@qu1ck Thanks! I will look into that. that would be halfway there already. Seems like I have to open the GUI anyways to check (and adjust) the output.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.