Pcbnew export/import scripting functions



  1. I am not able to find pcbnew export/import scripting
    representation of PCBnew -> File -> Export Specttra DSN, etc.

  2. what am I missing?

Thank you.

Announcing kicad_freerouting-plugin

I’m 99% sure import/export functionality is not available from python.
If you need it file a bug on launchpad. At least a few people will click “affects me too” button that I know.

  1. I filed a bug, thank you:

  2. current python interface api is auto generated by swig

  3. do you by chance know:
    a) how hard would it be to make own swig-like stubs manually?
    b) are there examples of that?

  4. the entry points of interest seems to be here:

ExportSpecctraFile() @ 1084
ImportSpecctraSession() @ 1112




It’s not very hard to add swig stubs. It maybe not trivial to disentangle the API you are interested in so that you don’t have to expose a lot of unrelated stuff in swig which shouldn’t be accessible from outside pcbnew binary itself. I don’t know how hard it would be for export/import stuff, I’m just saying in general.

Here are couple examples:
Extending C++ code just for scripting:

Extending python code on top of generated stubs:

Of course changes to both require recompiling KiCad which I don’t think is avoidable.

  1. I sent basic pull request for the first issue I stumbled upon:

  2. way back launchpad was “so cool”, but now it feels like a nuisance compared to git

  3. would it make sense to ask core dev group to migrate to github? then whom/where to ask?


I believe your PR will be rejected with advice “run build from build directory which is already in gitignore”

Yeah launchpad is abandonware that is stuck in early '00s in terms of design language with it’s tiny fonts and UI elements. I dread opening it every time I have to and I have already advocated to switch to github/gitlab. Luckily devs are thinking about it:
also relevant thread
Generally communication with devs happens through the pidgeon mail launchpad mailing list.


That’s not important. What is important is the functional features. Launchpad is lousy. The bug report system is reeeally bad.


I agree, pretty much everything about it is bad. UI sucks, CI is non-existant, bug tracking is archaic, code review process is perfect example of how NOT to do that sort of thing.
Oh well. Maybe one of these days I’ll have some time to put together launchpad=>gitlab importer to help them with migration.


Still better than the github equivalent. Especially when it comes to searching for something.
Github also has no separation of tags, priority level and general state of the report. (One can simulate it by making lots of tags but that really seems like a hack. Hopefully MS will improve this part.)

So i think even if the launchpad bug report system has its drawbacks it still has a lot going for it.


If you want to run the script as an action plugin you can hack it via wx.UIActionSimulator() and you can simulate the keypress events in order to call the export action. It is quite hacky and it is not portable between languages. But it works.


please review a PR for this feature request:
Thank you.


While you’re at it, is it possible to also expose ArchiveModulesOnBoard? If is is, would you be willing to do it? I’ve got a python plugin, which archives complete project and I’ve got a couple of request to also save the footprints programmatically. As the backend already exists I’d rather use the KiCad’s internal code than rolling something on my own in python.

  1. sure, added support for ArchiveModulesOnBoard

  2. build settings:

  3. please review/build/test

# manual test session for "Tools -> Scripting Console"
# verify that "board-archive.pretty" folder is present
# result should be identical to "File -> Archive -> ..."
import os
import pcbnew
board = pcbnew.GetBoard()
board_path = board.GetFileName()
path_tuple = os.path.splitext(board_path)
board_prefix = path_tuple[0]
aStoreInNewLib = True
aLibName = "footprint-export"
aLibPath = board_prefix + "-archive.pretty"


Thanks. Much appreciated.


FYI: committed to master: