Help with Kicad (EEschema) Code - Where Schematic pages are loaded?

Hi guys, I am trying to make an experiment with Kicad code, to have a tool to export the old
format the schematic for using with old plugins/scripts while we don’t have such a thing implemented
with the python API. The branch I am using is 6.0.2

What I want to do is to pass the schematic through the command line, save the old format, and exit without interaction.
This thing already works. Once the schematic is open I can Ctrl+S to save the project with the legacy
format and extension.

Now, I want to make this automatic, to launch, save and close Eeschema. The save function I am using is
the same is found in the Ctrl+S shortcut.

So, I would like to ask you guys if you know where in the code I can call Save and Exit functions.
They could be executed as soon as all schematic pages are loaded.

So, does anybody have any hint where is this place/class/method?

… and possible data loss.
It’s impossible to save everything in legacy format because it doesn’t support all features.

But if you are brave enough to do that, then look at calls to SCH_PLUGIN::Save()

Meh it’s just an exporter. Conversion to other formats is always lossy. We have import from other formats too and accept some level of lossiness there, I’ve never really understood the opposition to treating old KICad formats in the same way.

It’s not just an exporter. It’s a hack that works in some cases by happenstance and not intention. Unlike exporters no dev made sure it produces anything sensible or sane.

I’m not sure how much data will be lost as I don’t keep track closely on what features were introduced when. It may be good enough for majority of simple schematics, I don’t know. But It will likely break with buses, hierarchical sheets etc.

Oh, I see. Thanks, @qu1ck .

I am already exporting in the legacy format however it requires human interaction to save the design.
So, if I find where the schematic is loaded I can try to save it and exit right after that without interaction.

The code is a bit hard to understand. But this is fine.
From inside the build folder, I am trying to find any occurrence of this "[.:]Save("

These files may give me a hint where I can look for a function that loads the schematics.

../../eeschema/eeschema.cpp
../../eeschema/sch_base_frame.cpp
../../common/settings/settings_manager.cpp

But I am not quite there yet.

sch_sexpr_parser.cpp

Thanks Jeff!

It looks like I have implemented what I wanted.

Example using multi page project

➜  release git:(702e8b8915) ✗ ./eeschema/eeschema test/board.kicad_sch
COMAND LINE PARSER
OpenProjectFiles (BEGIN)
Load design...
Loading file: /home/lheck/Documents/kicad-6.0.2-eeschema-min/build/release/test/board.kicad_sch
Loading file: /home/lheck/Documents/kicad-6.0.2-eeschema-min/build/release/test/female-adapter.kicad_sch
Loading file: /home/lheck/Documents/kicad-6.0.2-eeschema-min/build/release/test/mainboard.kicad_sch
Loading file: /home/lheck/Documents/kicad-6.0.2-eeschema-min/build/release/test/male-adapter.kicad_sch
OpenProjectFiles (END)
Saving project files
Output: /home/lheck/Documents/kicad-6.0.2-eeschema-min/build/release/test/board.sch
Output: /home/lheck/Documents/kicad-6.0.2-eeschema-min/build/release/test/female-adapter.sch
Output: /home/lheck/Documents/kicad-6.0.2-eeschema-min/build/release/test/mainboard.sch
Output: /home/lheck/Documents/kicad-6.0.2-eeschema-min/build/release/test/male-adapter.sch
COMAND LINE PARSER (END)

# Checkiking generated files
➜  release git:(702e8b8915) ✗ ls -ltr test/*.kicad_sch test/*.sch
-rw-rw-r-- 1 lheck lheck  14855 Mar  8 21:07 test/board.kicad_sch
-rw-rw-r-- 1 lheck lheck  13725 Mar  8 21:07 test/male-adapter.kicad_sch
-rw-rw-r-- 1 lheck lheck 144799 Mar  8 21:07 test/mainboard.kicad_sch
-rw-rw-r-- 1 lheck lheck  22197 Mar  8 21:07 test/female-adapter.kicad_sch
-rw-rw-r-- 1 lheck lheck   1568 Mar 12 19:02 test/board.sch
-rw-rw-r-- 1 lheck lheck   3576 Mar 12 19:02 test/female-adapter.sch
-rw-rw-r-- 1 lheck lheck   2444 Mar 12 19:02 test/male-adapter.sch
-rw-rw-r-- 1 lheck lheck  29319 Mar 12 19:02 test/mainboard.sch

Example using single page project

➜  release git:(702e8b8915) ✗ ./eeschema/eeschema board.kicad_sch     
COMAND LINE PARSER
OpenProjectFiles (BEGIN)
Load design...
Loading file: /home/lheck/Documents/kicad-6.0.2-eeschema-min/build/release/board.kicad_sch
OpenProjectFiles (END)
Saving project files
Output: /home/lheck/Documents/kicad-6.0.2-eeschema-min/build/release/board.sch
COMAND LINE PARSER (END)

# Checking generated file
➜  release git:(702e8b8915) ✗ ls -ltr *.kicad_sch *.sch    
-rw-rw-r-- 1 lheck lheck 207671 Mar  9 10:38 board.kicad_sch
-rw-rw-r-- 1 lheck lheck  41447 Mar 12 19:02 board.sch

Do you guys know if it is possible to generate a missing -cache.lib file automatically from the .kicad_sch loaded, somehow? I also need this file for my application to work.

I guess it would probably require a similar hack to extract the symbols from *.kicad_sch. But if you still have the symbol libraries that were used in KiCad 5 format, then KiCad 5 (maybe 6 also?) could recreate (“rescue”) the cache file from them.

In KiCad 5, the cache file is actually not needed if all symbols (with the matching versions) can be found in the configured libraries. In KiCad 6 as well, but it displays a different warning dialog, if I remember correctly…

Yeh, I was looking for a way to export this from .kicad_sch. But there is not a method that does that recreating the whole file assuming no-cache library file was found. At least I could not find any related method yet. But maybe I can find something in Kicad 5 or 5.99.

Now, if there is no method like this, I am wondering what should I do to manually create this file, instead.

The generated .sch, for my board, looks good, and nothing is missing. But the external program that uses my .sch file relies on this file to generate the schematic symbols.

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