MCPcopy Index your code
hub / github.com/SLiCAP/SLiCAP_python / backAnnotateSchematic

Function backAnnotateSchematic

SLiCAP/SLiCAPkicad.py:240–270  ·  view source on GitHub ↗

#. Replaces text labels on a KiCAD schematic with : #. Creates drawing-size ``svg`` and ``pdf`` images of the annotated schematic #. Saves the annotated schematic :param sch: File of the KiCAD schematic with annotation text labels;

(sch, opinfo)

Source from the content-addressed store, hash-verified

238 return netlist, subckt
239
240def backAnnotateSchematic(sch, opinfo):
241 """
242 #. Replaces text labels <label> on a KiCAD schematic with <label>:<opinfo[label]>
243 #. Creates drawing-size ``svg`` and ``pdf`` images of the annotated schematic
244 #. Saves the annotated schematic
245
246 :param sch: File of the KiCAD schematic with annotation text labels;
247 location relative to project directory
248 :type sch: str
249
250 :param opinfo: Dictionary with key-value pairs:
251
252 - key: label text
253 - value: text to be appended to the label
254 :return: None
255 :rtype: NoneType
256 """
257 f = open(sch, "r")
258 schematic = f.read()
259 f.close()
260 replacements = {}
261 for name in opinfo.keys():
262 m = re.search(rf'(\(text "{name})(\:\s?[+-]?\d+\.?\d*)?([eE][+-]?\d+)?"', schematic)
263 if m != None:
264 replacements[m.group(0)] = m.group(1) + ': {:8.2e}"' .format(opinfo[name])
265 for replacement in replacements.keys():
266 schematic = schematic.replace(replacement, replacements[replacement])
267 f = open(sch, "w")
268 f.write(schematic)
269 f.close()
270 KiCADsch2svg(sch)
271
272if __name__=='__main__':
273 from SLiCAP import initProject

Callers

nothing calls this directly

Calls 4

KiCADsch2svgFunction · 0.85
groupMethod · 0.80
formatMethod · 0.80
writeMethod · 0.80

Tested by

no test coverage detected