GUI agnostic import for Specctra session to allow headless/scripted auto-routing

I’ve just posted a feature request to the Gitlab repo but I’m interested if anyone here maybe has novel solutions (or also would appreciate the feature).

Problem Description

The current implementation of importing a Specctra Session to a board in pcbnew requires an active window of pcbnew. This removes the ability to have a headless scripting a process of: pcbnew exports Specctra DSN, auto-route board + export Specctra session file, pcbnew imports Specctra session file and saves board.

Problem Details

I’m approaching this from the perspective of the python swig interface that exposes the pcbnew.ImportSpecctraSES but the major changes that would need to be made are in the specctra import cpp source. My hope would be that the import could be abstracted to take a BOARD type input and then directly add the imported elements to that object. From the perspective of the python interface, it might end up looking something like the python shell snippet below.

Python 3.10.10 (main, Feb  8 2023, 14:50:01) [GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pcbnew
>>> board = pcbnew.LoadBoard("./my_kicad_pcb.kicad_pcb")
>>> pcbnew.newImportSpecctraSES(board, "./")

As a little more background, I am in the process of trying to make scripts to completely automatically generate very simple custom PCBs. My current workaround is to use an xvfbWrapper contextmanager to open the target board file with the GUI, import the SES file and then save the output (the same strategy that a lot of KiCad automation scripts have implemented). It does work but it’s extremely brittle.

Side note: I’m not sure on the etiquette/usefulness of cross posting this as both a feature request and discussion topic here. Someone please feel free to advise me if you think there’s a better approach to my posts.

[Edited to remove excessive quoting. @bidrohini please do not quote large amounts of a previous post, especially as you didn’t delimit the quoted post and your comments correctly anyway. - Mod]

Your feature request for headless importing of Specctra sessions in pcbnew is a valid and useful one, especially for those who want to automate the PCB design process. One potential solution to this problem could be to create a new function in the specctra import cpp source that takes a BOARD type input as you suggested, and then directly adds the imported elements to that object.

Another possible approach could be to modify the existing pcbnew.ImportSpecctraSES function to take a BOARD type input as well, which would allow for the importing of the Specctra session without requiring an active window of pcbnew. This modification could be made in the python swig interface, as you mentioned.