How to initialize your KiCAD 5 project on the command line
In case you are using KiCAD 6 (released in 2021), this is not the right post for you ! See How to initialize your KiCAD 6 project on the command line
*Note:*This script initializes a KiCAD project in the recommended configuration (i.e. with project-specific footprint and symbol libraries). In case you want to initialize an empty project, see How to initialize an empty KiCAD project on the command line
TL;DR:
Inside the directory where you want to create the project, run
wget -qO- https://techoverflow.net/scripts/kicad-init.sh | bash /dev/stdin MyProject
You should replace MyProject
(at the end of the command) with your project name.
*Note:*This will initialize an empty KiCAD project without any libraries. This is equivalent to creating a new project in KiCAD itself (using the GUI).
How it works
Our script is a simple bash
script that creates the files that KiCAD creates when manually creating a new project.
It will create these files (MyProject
is the default project name, but you can modify it using a command line argument):
MyProject.pro
: The project fileMyProject.sch
: The empty schematicMyProject.kicad_pcb
: The empty PCBsym-lib-table
: List of schematic symbol libraries for the projectlibraries/MyProject.lib
: Schematic symbol librarylibraries/MyProject.dcm
: Metadata for schematic symbols.fp-lib-table
: List of footprint libraries for the projectlibraries/footprints
: The folder where project-specific footprints (.kicad_mod
files) are storedlibraries/3D
: This folder should be used to store 3D models (e.g. STEP files)
The files are modelled after KiCAD 5.1.4 but we expect them to work with any recent KiCAD version.
#!/bin/bash
# TechOverflow KiCAD project initializer (with project FP & SYM libraries)
# Usage: $0
if [ $# -ne 1 ]
then
echo "Usage: $0 "
exit 1
fi
# Compute project name and path
proj=$(basename "$1")
dir=$(dirname "$1")
# Create project file
cat < ${1}.pro
update=22/05/2015 07:44:53
version=1
last_client=kicad
[general]
version=1
RootSch=
BoardNm=
[pcbnew]
version=1
LastNetListRead=
UseCmpFile=1
PadDrill=0.600000000000
PadDrillOvalY=0.600000000000
PadSizeH=1.500000000000
PadSizeV=1.500000000000
PcbTextSizeV=1.500000000000
PcbTextSizeH=1.500000000000
PcbTextThickness=0.300000000000
ModuleTextSizeV=1.000000000000
ModuleTextSizeH=1.000000000000
ModuleTextSizeThickness=0.150000000000
SolderMaskClearance=0.000000000000
SolderMaskMinWidth=0.000000000000
DrawSegmentWidth=0.200000000000
BoardOutlineThickness=0.100000000000
ModuleOutlineThickness=0.150000000000
[cvpcb]
version=1
NetIExt=net
[eeschema]
version=1
LibDir=
[eeschema/libraries]
EOT
# Create schematic file
cat < ${1}.sch
EESchema Schematic File Version 2
EELAYER 25 0
EELAYER END
\$EndSCHEMATC
EOT
cat < ${1}.kicad_pcb
(kicad_pcb (version 4) (host kicad "dummy file") )
EOT
#
# Create schematic symbol library mapping
#
mkdir -p ${dir}/libraries
cat < ${dir}/sym-lib-table
(sym_lib_table
(lib (name ${1})(type Legacy)(uri \${KIPRJMOD}/libraries/${proj}.lib)(options "")(descr ""))
)
EOT
cat < ${dir}/libraries/${proj}.lib
EESchema-LIBRARY Version 2.4
#encoding utf-8
#
#End Library
EOT
cat < ${dir}/libraries/${proj}.dcm
EESchema-DOCLIB Version 2.0
#
#End Doc Library
EOT
#
# Create footprint library mapping (just an empty directory)
#
mkdir -p ${dir}/libraries/footprints
cat < ${dir}/fp-lib-table
(fp_lib_table
(lib (name ${proj})(type KiCad)(uri \${KIPRJMOD}/libraries/footprints)(options "")(descr ""))
)
EOT
#
# Create directory for 3D models.
# The search path might need to be configured manually
# since it's not stored in a project
#
mkdir -p ${dir}/libraries/3D
#
# Create .gitignore
#
cat < .gitignore
*-bak
*-cache*
*-bak*
_autosave*
EOT
Run e.g. using
bash kicad-init.sh MyProject