Skip to content

Instantly share code, notes, and snippets.

@leoheck
Last active February 17, 2023 06:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leoheck/0023e5118fb537147f045a2df7af1c3e to your computer and use it in GitHub Desktop.
Save leoheck/0023e5118fb537147f045a2df7af1c3e to your computer and use it in GitHub Desktop.
Exports all Schematics pages and every Layer of the PCB in individual SVG files.
#!/bin/bash
# Usage: kicad_cli_all KICAD_PRO
kicad_pro=${1}
if [[ ! -f "${kicad_pro}" ]]; then
echo "Kicad project '${kicad_pro}' is missing"
exit
fi
filename=$(basename -- "${kicad_pro}")
proj_extension="${filename##*.}"
proj_name="${filename%.*}"
svg_path=export_svg
sch_path=${svg_path}/sch
pcb_path=${svg_path}/pcb
rm -rf ${svg_path}
mkdir -p ${sch_path}
mkdir -p ${pcb_path}
echo
kicad_sch="${proj_name}.kicad_sch"
cmd="kicad-cli sch export svg --black-and-white --no-background-color --output \"${sch_path}\" \"${kicad_sch}\""
echo "${cmd}"
eval ${cmd}
# It may be necessary to rename pages
for kicad_sch in ${sch_path}/*; do
rename "s/${proj_name}-//g" "${kicad_sch}"
done
echo
kicad_pcb="${proj_name}.kicad_pcb"
pcb_layers=$(grep "^[ \t]\+([0-9][0-9]* " "${proj_name}.kicad_pcb")
layers_name=$(grep "^[ \t]\+([0-9][0-9]* " "${proj_name}.kicad_pcb" | cut -d\" -f2 )
for layer_name in ${layers_name[@]}; do
layer_id=$(echo "${pcb_layers}" | grep "${layer_name}" | sed "s/[ \t]*(//g" | cut -d " " -f 1 | xargs printf "%02d")
cmd="kicad-cli pcb export svg --page-size-mode 0 --black-and-white \"${kicad_pcb}\" --output \"${pcb_path}/layer-${layer_id}.svg\" --layers \"${layer_name},Edge.Cuts\""
echo "${cmd}"
eval ${cmd}
echo
echo
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment