~cern-kicad/kicad/kicad-pns-tom

« back to all changes in this revision

Viewing changes to scripts/lib_convert.py

  • Committer: Maciej Suminski
  • Date: 2013-08-02 13:57:24 UTC
  • mfrom: (4024.1.238 kicad)
  • mto: This revision was merged to the branch mainline in revision 4221.
  • Revision ID: maciej.suminski@cern.ch-20130802135724-gix6orezshkukodv
Upstream merge.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
# Convert a footprint library from one format to another, e.g. legacy to pretty.
 
4
 
 
5
# 1) Build target _pcbnew after enabling scripting in cmake.
 
6
# $ make _pcbnew
 
7
 
 
8
# 2) Changed dir to pcbnew
 
9
# $ cd pcbnew
 
10
# $ pwd
 
11
# build/pcbnew
 
12
 
 
13
# 3) Entered following command line, script takes to arguments: oldLibPath & newLibPath
 
14
# $ PYTHONPATH=. <path_to>/lib_convert.py /usr/local/share/kicad/modules/smd_dil.mod /tmp/smd_dil.pretty
 
15
 
 
16
# 4) inspect one footprint found in new librarypath /tmp/smd_dil
 
17
# $ less /tmp/smd_dil/msoic-10.kicad_mod
 
18
 
 
19
 
 
20
from __future__ import print_function
 
21
from pcbnew import *
 
22
import sys
 
23
 
 
24
if len( sys.argv ) < 3 :
 
25
    print( "usage: script srcLibraryPath dstLibraryPath" )
 
26
    sys.exit(1)
 
27
 
 
28
 
 
29
src_libpath = sys.argv[1]
 
30
dst_libpath = sys.argv[2]
 
31
 
 
32
 
 
33
src_type = IO_MGR.GuessPluginTypeFromLibPath( src_libpath );
 
34
dst_type = IO_MGR.GuessPluginTypeFromLibPath( dst_libpath );
 
35
 
 
36
src_plugin = IO_MGR.PluginFind( src_type )
 
37
dst_plugin = IO_MGR.PluginFind( dst_type )
 
38
 
 
39
try:
 
40
    dst_plugin.FootprintLibDelete( dst_libpath )
 
41
except:
 
42
    None    # ignore, new may not exist if first run
 
43
 
 
44
dst_plugin.FootprintLibCreate( dst_libpath )
 
45
 
 
46
list_of_parts = src_plugin.FootprintEnumerate( src_libpath )
 
47
 
 
48
for part_id in list_of_parts:
 
49
    module = src_plugin.FootprintLoad( src_libpath, part_id )
 
50
    dst_plugin.FootprintSave( dst_libpath, module )
 
51