added support for footprint libs
This commit is contained in:
22
exporter.py
22
exporter.py
@@ -3,10 +3,11 @@ import re
|
||||
import pprint as ppr
|
||||
from kiutils.libraries import LibTable
|
||||
from kiutils.symbol import SymbolLib
|
||||
from kiutils.footprint import Footprint
|
||||
import tomli
|
||||
import tomli_w
|
||||
import pathlib
|
||||
|
||||
import glob
|
||||
|
||||
printer = ppr.PrettyPrinter(width=900)
|
||||
pprint = printer.pprint
|
||||
@@ -43,8 +44,7 @@ def main():
|
||||
if libs.type == 'sym_lib_table':
|
||||
write_syms_to_file(f, lib)
|
||||
if libs.type == 'fp_lib_table':
|
||||
pass
|
||||
# TODO
|
||||
write_fps_to_file(f, lib)
|
||||
pass
|
||||
|
||||
def write_syms_to_file(f, lib):
|
||||
@@ -55,6 +55,14 @@ def write_syms_to_file(f, lib):
|
||||
print(f'{lib.name}:{sym}')
|
||||
f.write(f'{lib.name}:{sym}\n')
|
||||
|
||||
def write_fps_to_file(f, lib):
|
||||
if lib.type == 'KiCad':
|
||||
fps = footprints_to_list(lib.uri)
|
||||
if fps:
|
||||
for fp in fps:
|
||||
print(f'{lib.name}:{fp}')
|
||||
f.write(f'{lib.name}:{fp}\n')
|
||||
|
||||
def load_envs(args):
|
||||
if args.e:
|
||||
with open(args.e, 'rb') as settings:
|
||||
@@ -83,10 +91,14 @@ def table_to_dict(filename, envs = None):
|
||||
|
||||
def symbols_to_list(path):
|
||||
sym = SymbolLib.from_file(path)
|
||||
|
||||
symlst = [s.entryName for s in sym.symbols if (s.inBom and not s.isPower)]
|
||||
|
||||
return symlst
|
||||
|
||||
def footprints_to_list(path):
|
||||
fplst = [Footprint.from_file(mod).entryName
|
||||
for mod in glob.glob(f'{path}/*.kicad_mod')
|
||||
if not Footprint.from_file(mod).attributes.excludeFromBom]
|
||||
return fplst
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user