Include symbol name in BOM export?

Is there a way using the KiCad CLI to include the symbol name or library link information as a column when exporting a BOM from a schematic file? Similar to how you can use “${DNP}” as one of the fields, maybe there’s a magic variable name like that I can invoke?

Alternatively, is there a simple way to get the information shown from the Tools > Edit Symbol Library Links dialog? I could match up library references with RefDes from the exported BOM in that case.

I’m hoping not to have to write a schematic file parser just to get this info.

The context for this is writing a script that checks each line item in a BOM against a database of approved parts that I’m creating, where I will enter for a given MPN what footprints and symbols are allowed to be used.

Thanks!

${SYMBOL_NAME} and ${SYMBOL_LIBRARY}.

image

Thanks for this suggestion. Those variables work for me when I add a new field to a given symbol like your image shows. I would need to add fields to every component in the schematic though to use that approach - not hard to do but does add some manual steps and I’m trying to automate this as much as possible. I can make it work this way if I can’t find a way to use the CLI alone.

This may come as a surprise, but with the Edit Symbol Fields dialog you can actually edit symbol fields. You can group symbols by some field which groups all symbols into one or two rows and write for example ${SYMBOL_NAME} once or twice. Or you can leave them totally ungrouped, select the whole column with Shift+click and paste text there.

It’s good to know that there are some rough edges in this dialog, you may have to accept and close it, then reopen to see the result with string variable replacement working in the BOM Export tab of the dialog.

1 Like

The UI weirdness around those fields threw me off at first, once I close and re-open the dialog I get the correct behavior as you described. The fields show up now if I do a BOM export from within KiCad, but I still can’t get them to show up in the CLI output yet.

I’m following the CLI documentation for specifying output fields, but for some reason I’m not getting any special fields to output properly if I include them in arguments.

Not specifying fields, per docs the defaults are “Reference,Value,Footprint,${QUANTITY},${DNP}”:

/path/to/kicad-cli sch export bom --output /path/to/bom.csv /path/to/schematic.kicad_sch

# This works as expected, CSV looks like:
"Refs","Value","Footprint","Qty","DNP"
"C1","22uF","","1",""
...

If I do specify fields, even ones that are included in the defaults, they don’t work:

/path/to/kicad-cli sch export bom --output /path/to/bom.csv --fields Reference,Value,${DNP},${SYMBOL_NAME} /path/to/schematic.kicad_sch

# Header in CSV:
"Reference","Value"
"C1","22uF"
...

No change if I put the fields string in quotes either.

Since I have the SYMBOL_NAME and SYMBOL_LIBRARY fields defined in the Edit Symbol Fields dialog now I tried referencing them without the ${} on the CLI - also did not work.

I’m using KiCad 8.0.6 on macOS, in case that’s relevant.

Any idea what I’m missing here?

Single or double quotes? The Unix shell will expand ${VAR} inside double quotes and the expansions will be empty as they are unknown to the shell.

1 Like

Aha! That did it. Works properly now when I use single quotes around the string. Thanks for catching that!