I ended up writing some scripts to migrate all my old projects across. Details here in case anyone else finds it useful. Written in Windows PowerShell, as a chance to learn something new. I definitely prefer Linux grep+sed!
Schematic library names
The biggest problem with the schematic library/symbol names. It looks like my local copy of the standard symbols dates from KiCad v4 in 2017 (!) and when I upgraded to KiCad v5 I must have kept the same symbol library, probably to avoid all this hassle. Regardless, KiCad should build-in a better mechanism for automated migration when it loads old projects that use older symbol libraries.
To build a file of all the KiCad *.sch
schematic filenames on my computer:
Get-ChildItem 'C:\projects' -recurse -include *.sch | select-object fullname | sort fullname | Out-File schematic_files.txt
To load each schematic file in turn, parse for symbol names, output to a single file, then strip out duplicate symbol names:
$files = Get-Content schematic_files.txt
ForEach ($item in $files){
Select-String -Path "$item" -CaseSensitive -Pattern '^L (.+) ' | %{ $_.Matches.Groups[1].Value } | Out-File symbols.txt -Append
}
Get-Content symbols.txt | Sort-Object | Get-Unique | Out-File symbols_unique.txt
(note this doesn’t work for even older EESchema v2 file format, which would need to be dealt with separately)
I then manually stripped out symbols from private libraries in symbols_unique.txt
, and turned it into a CSV file of search/replace pairs:
search, replace
power:\+3\.3V, power:+3V3
conn:Conn_01x02, Connector_Generic:Conn_01x02
conn:Conn_01x02_Female, Connector:Conn_01x02_Female
device:C, Device:C
device:CP1, Device:C_Polarized_US
device:R, Device:R
device:R_POT_TRIM, Device:R_Potentiometer_Trim
... more symbols here
(power:+3.3V is there because of a bug in KiCad when it loads an older version of the EESchema file format, probably the “.” character? Even though power:+3.3V exists as a symbol in the latest standard library, KiCad v6 can’t find it and puts it into a rescue library, so I’ve changed mine to +3V3 as a workaround)
Footprint changes
I decided against any sort of automated update to the latest footprints, given the chaos that could be caused on already-working PCBs. Better to deal with those manually as and when the PCB is revised.
3D models path
I wanted to rewrite ${KISYS3DMOD}
in every project *.kicad_pcb
file to use the new ${KICAD6_3DMODEL_DIR}
, but the more projects I migrated, the more models I found with changed filenames too. So this would have been better as a 2nd CSV file of search/replace pairs instead of hard-coding them into the script.
To migrate a single project at a time (so it can be loaded into KiCad and checked for any problems), I wrote this script:
# Migrate project schematic+PCB files from using KiCad v4 libraries to v5/6 with Windows PowerShell
# Run as:
# migrate.ps1 myproject
#
# sheffield_nikki, 20/Dec/2022
$item = $args[0] + '.sch'
$c = Get-Content $item
$csv = Import-csv -path "symbols_unique.csv"
ForEach ($i in $csv){
$s1 = '^L '+$i.search+' '
$s2 = 'L '+$i.replace+' '
$c = $c -replace $s1,$s2
}
Rename-Item -Path $item "kicad4-backup.sch"
Set-Content $item $c
# Migrate .kicad_pcb PCB file from KiCad v4/5 to KiCad v6
# only updates 3D models, doesn't rename any footprints
$item = $args[0] + '.kicad_pcb'
$c = Get-Content $item
$c = $c -replace 'model \${KISYS3DMOD}','model ${KICAD6_3DMODEL_DIR}'
$c = $c -replace 'Capacitors_THT\.3dshapes','Capacitor_THT.3dshapes'
$c = $c -replace 'Resistors_SMD\.3dshapes/R_0805\.wrl','Resistor_SMD.3dshapes/R_0805_2012Metric.wrl'
$c = $c -replace 'Capacitors_SMD\.3dshapes/C_0805\.wrl','Capacitor_SMD.3dshapes/C_0805_2012Metric.wrl'
# ... more models here
Rename-Item -Path $item "kicad4-backup.kicad_pcb"
Set-Content $item $c
The script only updates a single project *.sch
file, so for projects with multiple schematic sheets I did those with a separate version of the script. An improvement would be to automatically migrate all the *.sch
files in a project folder.