Pcbnew export/import scripting functions


#1

Hello.

  1. I am not able to find pcbnew export/import scripting
    http://docs.kicad-pcb.org/doxygen-python/index.html
    representation of PCBnew -> File -> Export Specttra DSN, etc.

  2. what am I missing?

Thank you.


Announcing kicad_freerouting-plugin
#2

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.


#3
  1. I filed a bug, thank you:
    https://bugs.launchpad.net/kicad/+bug/1824668

  2. current python interface api is auto generated by swig
    http://docs.kicad-pcb.org/doxygen-python/pcbnew_8py_source.html

  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
http://docs.kicad-pcb.org/doxygen/pcb__edit__frame_8h_source.html

ExportSpecctraFile()
http://docs.kicad-pcb.org/doxygen/specctra__export_8cpp_source.html
http://docs.kicad-pcb.org/doxygen/classPCB__EDIT__FRAME.html#aeaceecec60fa4b1290a7af8a4ab1531a

ImportSpecctraSession()
http://docs.kicad-pcb.org/doxygen/specctra__import_8cpp_source.html
http://docs.kicad-pcb.org/doxygen/classPCB__EDIT__FRAME.html#ad8b25ce84f3ec0602ec05dbe05ed0f30


#4

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.


#6
  1. I sent basic pull request for the first issue I stumbled upon:
    https://code.launchpad.net/~andrei-pozolotin/kicad/+git/kicad/+merge/366038

  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?


#7

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:
https://lists.launchpad.net/kicad-developers/msg39156.html
also relevant thread
https://lists.launchpad.net/kicad-developers/msg38081.html
Generally communication with devs happens through the pidgeon mail launchpad mailing list.


#8

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


#9

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.


#10

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.


#11

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.


#12

Guys,
please review a PR for this feature request:
https://code.launchpad.net/~andrei-pozolotin/kicad/+git/kicad/+merge/366082
Thank you.


#13

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.


#14
  1. sure, added support for ArchiveModulesOnBoard

  2. build settings:
    https://gist.github.com/Andrei-Pozolotin/30f76a71bae089c76b5d9dbe151d5ba2

  3. please review/build/test
    https://code.launchpad.net/~andrei-pozolotin/kicad/+git/kicad/+merge/366082

#
# 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"
pcbnew.ArchiveModulesOnBoard(aStoreInNewLib,aLibName,aLibPath)

#15

Thanks. Much appreciated.


#16

FYI: committed to master:
https://git.launchpad.net/kicad/commit/?id=3e4913adce86ea3955b7dac39703425d9cb2c41e