Open leoheck opened 2 years ago
Ah, I found out that if there are multiple instances of sheets inside the schematic, the parser returns a SexpList, but sometimes there is just a single instance, where the parser returns a single object and then there are times where there is no instance. So, I have to treat each case differently.
This problem is mentioned in the Readme, paragraph starting with If you are not sure whether a key in the object model holds a single expression
.
What KicadPCB
does is adding a set of keywords to a class attribute _defaults. So, you can either modify _defaults
directly, or write your own class deriving from KicadPCB
and override _defaults
.
The _defaults
attribute is read by sexp_parser.SexpParser
here. Check the docstring of sexp_parser.Sexp._addDefaults() for more information.
Nice, thanks for a detailed explanation. This repo could have a kicad_sch.py too, what do you think? I will try to make a simple one for me, then I could make a PR if you think it is a valid idea.
Since I have started this I will keep a (Work in progress) PR here so we can collaborate, if you are not interested just close it and it is ok. Cool?
Hi @realthunder
I am trying to parse the hierarchy of Kicad schematics, which is not a direct task. Then I am using your parser to tackle this issue.
I can get data from sheet instances... but sometimes the parser returns things that are not SexpParser objects. Is this correct?. This happens in the extra .kicad_sch files, but not with the main .kicad_sch
Then I am using this try...expect to solve that. But I would like to check with you if this is the correct behavior of kicad_parser.
My current result to show UUID, Sheet Instance Name, and Sheet Instance File is something like this.