File: lib_convert.py

package info (click to toggle)
kicad 9.0.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 770,320 kB
  • sloc: cpp: 961,692; ansic: 121,001; xml: 66,428; python: 18,387; sh: 1,010; awk: 301; asm: 292; makefile: 227; javascript: 167; perl: 10
file content (45 lines) | stat: -rw-r--r-- 1,266 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/python

# Convert a footprint library from one format to another, e.g. legacy to pretty.

# 1) Entered following command line, script takes to arguments: oldLibPath & newLibPath
# $ PYTHONPATH=. <path_to>/lib_convert.py /usr/local/share/kicad/modules/smd_dil.mod /tmp/smd_dil.pretty

# inspect one footprint found in new librarypath /tmp/smd_dil.pretty


from __future__ import print_function
from pcbnew import *
import sys

if len( sys.argv ) < 3 :
    print( "usage: script srcLibraryPath dstLibraryPath" )
    sys.exit(1)


src_libpath = sys.argv[1]
dst_libpath = sys.argv[2]


src_type = IO_MGR.GuessPluginTypeFromLibPath( src_libpath );
dst_type = IO_MGR.GuessPluginTypeFromLibPath( dst_libpath );

src_plugin = IO_MGR.PluginFind( src_type )
dst_plugin = IO_MGR.PluginFind( dst_type )

try:
    dst_plugin.DeleteLibrary( dst_libpath )
except:
    None    # ignore, new may not exist if first run

dst_plugin.CreateLibrary( dst_libpath )

list_of_parts = src_plugin.FootprintEnumerate( src_libpath )

ii = 0;
for part_id in list_of_parts:
    footprint = src_plugin.FootprintLoad( src_libpath, part_id )
    dst_plugin.FootprintSave( dst_libpath, footprint )
    ii = ii+1
    print( ii, footprint.GetFPID().GetUniStringLibId(), "->", dst_libpath )