Fixes https://gitlab.com/kicad/code/kicad/-/issues/15961
- code refactory. - allows export to be done from kicad-cli (kicad-cli code is not yet updated) Need more work.