I have made a bunch of footprints over the years, and currently trying to clean them up and get them consistent. For example most dont have a %R
, e.g.
(fp_text user %R (at 0 6.35 90) (layer F.Fab)
(effects (font (size 1 1) (thickness 0.15)))
)
I started writing a python script to set silkscreen line width sizes, and silkscreen text thickness, and ref designator text.
from pathlib import Path
import re
p = Path.cwd().parent.joinpath('mylib.pretty')
files = p.glob('*.kicad_mod')
CONVENTIONS = {
'silkscreen_line_width' : ['0.15', r'(?<=layer "F.SilkS"\) \(width )(\d.\d\d?)'],
'silkscreen_text_width' : ['0.15', r'(?<=\(layer "F.SilkS"\)\n \(effects \(font \(size 1 1\) \(thickness )(\d.\d\d?)'],
'silkscreen_ref' : ['REF**', r'(?<=fp_text reference ")([a-zA-Z0-9*]+)(?=")'],
}
for filename in files:
print('Opening ', filename)
with open(filename, 'r') as f:
content = f.read();
edited = content
for convention, [correct, pattern] in CONVENTIONS.items():
edited = re.sub(pattern, correct, edited)
with open(filename, 'w') as f:
content = f.write(edited);
However when it comes to added attributes that arent already there it gets tricker.
I have searched for docs on the *.kicad_mod file format but did not find.
I did come across this: https://gitlab.com/kicad/libraries/kicad-footprint-generator which is about making new footprints, not editing existing footprints.
Is there a generic KiCAD lib for altering kicad_mod
files? failing that looking at the format it seems like some sort of LISP format. Is there a generic LISP file parser/modifier in python? Similar to how you get them comes for JSON/XML?