Modify kicad schematic with python

Hi ! I’m begginer in Kicad, I’m writting a script using pcbnew to place component in the pcb viewer of Kicad. I’m able to generate a netlist but I have a problem. I have no idea to convert my netlist into .sch to create the schematic file. Eeschema API seems not ready, so I can’t use it.

I saw an old post where @bobc managed to write a code converting a netlist into a .sch file, so it’s possible !

Does anyone have an idea for modifying or creating instances in kicad schematic ?

Thanks !!

1 Like

Depending on what exactly you are attempting to do, you may find skidl useful to describe schematics in Python and export netlist for use in PCB editor.

If you describe a little more about what you are working on, you may get more targeted answers.

Edit: just read the linked thread and realized skidl has already been mentioned. Apologies for treading the same ground!

Thanks for your answer. The main problem is that Kicad schematic can only export netlist, the import is not posible. I did some research on the .kicad_sch file format to know if an existing library that could help me modify/create a schematic. Without success…
I will try to write in a sch file to modify schematic by myself, it’s the “easiest” way I guess.

It wouldn’t make a lot of sense for KiCad to import a netlist directly into the schematic editor. As described in the linked thread, a schematic is much more than just a netlist, it is graphical documentation and a place to check logic (amongst other things). You can work around that with externally edited schematic files if you really need though.

There are multiple 3rd party projects that maintain readers/writers for the KiCad schematic format. I believe Kiutils is the most current python project: GitHub - mvnmgrx/kiutils: Simple and SCM-friendly KiCad file parser based on Python dataclasses for KiCad 6.0 and up.

1 Like

Thank you for your reply. I will do some research on this bookstore. I need to automatically place components, i.e. holes and pads by retrieving a dictionary list describing each component (name, net, etc…) I manage to generate the desired point cloud in the pcb editor using the pcbnew API and exporting a .kicad_pcb file. But I can’t generate a .sch file and I can’t establish the connections between my components and my net with pcbnew.

I still don’t fully know why you are doing what you are doing (and that is okay) but there are similar projects out if all you want is a programmatically defined board without schematic/documentation.

I’ve not personally used PCBflow (or Cuflow, which it is based on), but it does seem like what you are currently trying to do without the fuss of the KiCad python linkings.

1 Like

Hi ! thanks for tour time. For now, I can only save a .kicad_pcb with my code but I would like to save a .kicad_sch too with net connection etc… I can’t find any libraries for directly modifying a .sch file. I know that kicad is make to begin with a schematic and then work with pcbnew.

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