Python API's ExportSpecctraDSN() broken in nightly?

Hi Everyone!

I’m trying to use the python interface of pcbnew to export/import Specctra DSN/SES files, but I’m running into some trouble.

I’ve installed the KiCad nightly PPA on Ubuntu 20.04 following the instructions here. However, when I call ExportSpecctraDSN(“output.dsn”) it returns false. Other commands seem to work fine such as printing out the modules in the file.

Does anyone have any suggestions for how to debug further into what might be going wrong? I’ve checked that exporting works from the pcbnew UI. Importing is broken similarly.

import sys                                                                                                                                                     
sys.path.insert(1, '/usr/lib/kicad-nightly/lib/python3/dist-packages/')                                                                                        
import pcbnew                                                                                                                                                  
b = pcbnew.LoadBoard(sys.argv[1])                                                                                                                              
for m in b.GetModules():                                                                                                                                       


If you look at the code for that function it depends on pcbnew window being open.

You can’t use this API from pure python session, only from pcbnew scripting console or plugin.

Wow, thanks for the quick response! I appreciate it! (Your username is very apt.)

Do you have any other suggestions for how to automate SpecctraDSN exporting from the commandline, before I consider trying to factor out the import/export myself?

If you are up to it, refactoring kicad code to separate specctra related code from UI stuff so that the api doesn’t need a window is the only way I can think of.

There has been developer discussion about these kind of things in general, they want to separate logic from the UI. At the moment those two are too intertwined. But that takes much work and time. Unfortunately the developers haven’t been willing to write out any details which could help outsiders, so you just have to ask about this detail in the mailing list. IIRC producing output files has been one area which has been mentioned explicitly.

Thanks everyone!

I’ve downloaded the source and have pcbnew building with the following config:

cmake  -DCMAKE_BUILD_TYPE=Release \

make -j 12 pcbnew

However, when I run the following:

import sys
sys.path.insert(1, "/home/gtaubman/kicad/build/release/pcbnew/")
import pcbnew

I get the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/gtaubman/kicad/build/release/pcbnew/", line 903, in <module>
AttributeError: module '_pcbnew' has no attribute 'PCB_MODULE_ZONE_AREA_T'

Does anyone have any suggestions for what i might be doing wrong when building, such that some symbols are not available but others are?

It’s not enough to import module, you need to put the python dynamic library that uses in LD_LIBRARY_PATH or whatever python uses to look for it’s libraries. I think it’s called either or pcbnew.pyd on linux, should be somewhere in your pcbnew build directory.

You can muck around with environment variables or just run make installto have kicad install script put all the files somewhere system will find them, ususally /usr/local. You also may have to run ldconfig once.

That did it! Time to see if I can do some gentle refactoring now. Thanks again!

For anyone following along at home, the following worked for me:

export LD_LIBRARY_PATH=/home/$USER/kicad/build/release/pcbnew/

>>> import sys
>>> sys.path.insert(1, "/home/gtaubman/kicad/build/release/pcbnew/")
>>> import pcbnew
1 Like

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