Custom Schematic Annotation

Sorry if this is a noob question, but I am trying to write a script to annotate schematic parts in a nonstandard way. Instead of iterating numerically, I want to iterate switches with their keynames - numlock, F1, backspace, etc. Essentially I want to import a textfile with the names and have kicad assign them to the switches, but I can’t find any documentation on how to edit the schematic with scripts. In fact, I can hardly find any documentation on writing ANY script for kicad. Any help or point in the right direction would be appreciated. Thanks

I think the codebase that EEschema runs on (still) is not capable of that (yet).
The developers work on getting EEschema to the same standard as PCBnew (where there is scripting support), so you’ll probably have to wait on that (I’d say not before Q3/17).

If you need that functionality now you’d have to manipulate the .sch file outside of KiCAD.
The file is human readable and relatively easy to understand, example for an entry (note the U103 in there - 2 places afai-can-see):

$Comp
L CurrentDrv_PSSI2021SAY_SOT353 U103
U 1 1 56FD43D6
P 1325 6275
F 0 "U103" H 1368 6807 50  0000 C CNN
F 1 "CurrentDrv_PSSI2021SAY" H 1368 6715 50  0000 C CNN
F 2 "SOTx:SOT-353" H 1325 6275 10  0001 C CNN
F 3 "E:\\Datasheets\\Electronics\\IntegratedCircuits\\CurrentSources\\NXP_LED-Driver-Transistor_PSSI2021SAY.pdf" H 1325 6275 10  0001 C CNN
F 4 "PSSI2021SAY,115" H 1325 6275 10  0001 C CNN "Manf#"
F 5 "NXP" H 1325 6275 5   0001 C CNN "Manf"
F 6 "_" H 1325 6275 60  0001 C CNN "Optn"
    1    1325 6275
    1    0    0    -1  
$EndComp

PS: always interesting to hear the motivational reason to want certain features, what is yours?
Sound like you’re building a keyboard of sorts.

Yeah, I’m trying to make a custom mechanical keyboard. I was able to open the schematic file in Notepad++, and just looking it over I think I could make a simple find-replace script for it.

That’s the spirit! :smirk:

I found that KiCad insists reference names end with a digit, otherwise it refuses to export the netlist. So names like “numlock” would need to be “numlock1”.

It would be nice if this restriction was relaxed, names only need to be unique.

Eagle manages without the end-in-a-digit requirement, which is how I discovered it. In my Eagle converter, I add digits as neccessary.

There is no place in the design process where the end-in-a-digit is actually required, the names are just treated as identifiers, as long as the names are unique everything would work fine.

KiCad forces you to run the annotation on the netlist export if any name does not end in a digit, regardless of whether they have been manually named. If you cancel the annotation the export is also cancelled. KiCad only needs to check that no names end in “?”, and that all names are unique.

1 Like

Is there any opportunity moves to the 32-base numbering system? If KiCAD can have do it in hexadecimal or preferably in Base 32.