Tool to create symbol library from a directory of symbol files

I found the need for a tool to create a symbol library from a directory of symbol files and I couldn’t find a way to do it in kicad, so I wrote a python script to do it. It’s simple and may lack some error checking, but it works for me (so far). I’ll continue to refine it as the need arises. Feel free to download and try it.

2 Likes

I am not entirely sure, but I think long term goal for KiCad is to have support for both “packed” and “unpacked” footprint and symbol libraries.

Being able to do this conversion with kicad-cli does also seem logical to me, but a python script works too I guess.

Added a python script that updates all the symbols in a directory to the latest symbol format. A backup of the original file is created with .original appended to end of original filename. It’s available on my github page.

update_kicad_symbols.py

Nice idea, I like it. I suppose the need arose from downloading vendor symbols that (obviously) are stored as single files?
You got a “like” from me.

Why?

I mentioned kicad-cli earlier, and upgrading libraries is one of the things it can already do.

paul@cezanne:~$ kicad-cli sym upgrade
input: 1 argument(s) expected. 0 provided.
Usage: upgrade [--help] [--output OUTPUT_FILE] [--force] INPUT_FILE

Upgrades the symbol library to the current kicad version format

Positional arguments:
  INPUT_FILE    Input file 

Optional arguments:
  -h, --help    Shows help message and exits 
  -o, --output  Output file [nargs=0..1] [default: ""]
  --force       Forces the symbol library to be resaved regardless of versioning 

Impressively nerdy and uninformative.
The Linux man pages are full-blown user manuals compared to that.
No sale.

But I fail to see the usefulness of version conversion as well.
It can only be done on personal libraries.
Do they need a new version format? The old one still works, and utilizing the (few) new features will necessitate editing the symbols anyway.

There is no man page for kicad-cli. kicad-cli is relatively new. It’s also still being extended and a moving target. But if you want a man page for it, you’re free to write one :slight_smile:

But overall, the built in help output of kicad-cli is sparse but helpful. It always spits out some help if it is not a fully valid command. and the total amount of help built in is quite reasonable.

paul@cezanne:~$ kicad-cli
Usage: kicad-cli [--version] [--help] {fp,pcb,sch,sym,version}

Optional arguments:
  -v, --version  prints version information and exits 
  -h, --help     Shows help message and exits 

Subcommands:
  fp            Footprint and Footprint Libraries
  pcb           PCB
  sch           Schematics
  sym           Symbol and Symbol Libraries
  version       Reports the version info in various formats

paul@cezanne:~$ kicad-cli ml9104
Failed to parse 'ml9104', did you mean 'fp'
Usage: kicad-cli [--version] [--help] {fp,pcb,sch,sym,version}

Optional arguments:
  -v, --version  prints version information and exits 
  -h, --help     Shows help message and exits 

Subcommands:
  fp            Footprint and Footprint Libraries
  pcb           PCB
  sch           Schematics
  sym           Symbol and Symbol Libraries
  version       Reports the version info in various formats

paul@cezanne:~$ kicad-cli pcb
Usage: pcb [--help] {drc,export}

PCB

Optional arguments:
  -h, --help  Shows help message and exits 

Subcommands:
  drc        Runs the Design Rules Check (DRC) on the PCB and creates a report
  export     Export utilities (Gerbers, drill, position files, etc)

paul@cezanne:~$ kicad-cli pcb export
Usage: export [--help] {drill,dxf,gerber,gerbers,glb,ipc2581,pdf,pos,step,svg,vrml}

Export utilities (Gerbers, drill, position files, etc)

Optional arguments:
  -h, --help  Shows help message and exits 

Subcommands:
  drill      Generate Drill Files
  dxf        Generate a DXF from a list of layers
  gerber     Plot given layers to a single Gerber file
  gerbers    Plot multiple Gerbers for a PCB, including the ability to use stored board plot settings
  glb        Export GLB (binary GLTF)
  ipc2581    Export the PCB in IPC2581 format
  pdf        Generate PDF from a list of layers
  pos        Generate Position File
  step       Export STEP
  svg        Generate SVG outputs of a given layer list
  vrml       Export VRML

paul@cezanne:~$ kicad-cli pcb export drill
input: 1 argument(s) expected. 0 provided.
Usage: drill [--help] [--output OUTPUT_DIR] [--format FORMAT] [--drill-origin DRILL_ORIGIN] [--excellon-zeros-format ZEROS_FORMAT] [--excellon-oval-format OVAL_FORMAT] [--excellon-units UNITS] [--excellon-mirror-y] [--excellon-min-header] [--excellon-separate-th] [--generate-map] [--map-format MAP_FORMAT] [--gerber-precision VAR] INPUT_FILE

Generate Drill Files

Positional arguments:
  INPUT_FILE               Input file 

Optional arguments:
  -h, --help               Shows help message and exits 
  -o, --output             Output directory [nargs=0..1] [default: ""]
  --format                 Valid options excellon, gerber. [nargs=0..1] [default: "excellon"]
  --drill-origin           Valid options are: absolute,plot [nargs=0..1] [default: "absolute"]
  --excellon-zeros-format  Valid options are: decimal,suppressleading,suppresstrailing,keep. [nargs=0..1] [default: "decimal"]
  --excellon-oval-format   Valid options are: route,alternate. [nargs=0..1] [default: "alternate"]
  -u, --excellon-units     Output units, valid options:in,mm [nargs=0..1] [default: "mm"]
  --excellon-mirror-y      Mirror Y axis 
  --excellon-min-header    Minimal header 
  --excellon-separate-th   Generate independent files for NPTH and PTH holes 
  --generate-map           Generate map / summary of drill hits 
  --map-format             Valid options: pdf,gerberx2,ps,dxf,svg [nargs=0..1] [default: "pdf"]
  --gerber-precision       Precision of Gerber coordinates (5 or 6) [nargs=0..1] [default: 6]

For 2 reasons:

kicad-cli creates a new file, instead of updating the current file
kicad-cli updates only a single file each time it is invoked

The script that I wrote uses kicad-cli, but updates all the files in a directory, backing up the original files (if they were modified). I shared the scripts because I found them useful. Feel free to not use them.