You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.3 KiB

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