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.

45 lines
1.2 KiB

4 years ago
4 years ago
4 years ago
4 years ago
  1. #!/usr/bin/python
  2. # Convert a footprint library from one format to another, e.g. legacy to pretty.
  3. # 1) Entered following command line, script takes to arguments: oldLibPath & newLibPath
  4. # $ PYTHONPATH=. <path_to>/lib_convert.py /usr/local/share/kicad/modules/smd_dil.mod /tmp/smd_dil.pretty
  5. # inspect one footprint found in new librarypath /tmp/smd_dil.pretty
  6. from __future__ import print_function
  7. from pcbnew import *
  8. import sys
  9. if len( sys.argv ) < 3 :
  10. print( "usage: script srcLibraryPath dstLibraryPath" )
  11. sys.exit(1)
  12. src_libpath = sys.argv[1]
  13. dst_libpath = sys.argv[2]
  14. src_type = IO_MGR.GuessPluginTypeFromLibPath( src_libpath );
  15. dst_type = IO_MGR.GuessPluginTypeFromLibPath( dst_libpath );
  16. src_plugin = IO_MGR.PluginFind( src_type )
  17. dst_plugin = IO_MGR.PluginFind( dst_type )
  18. try:
  19. dst_plugin.DeleteLibrary( dst_libpath )
  20. except:
  21. None # ignore, new may not exist if first run
  22. dst_plugin.CreateLibrary( dst_libpath )
  23. list_of_parts = src_plugin.FootprintEnumerate( src_libpath )
  24. ii = 0;
  25. for part_id in list_of_parts:
  26. footprint = src_plugin.FootprintLoad( src_libpath, part_id )
  27. dst_plugin.FootprintSave( dst_libpath, footprint )
  28. ii = ii+1
  29. print( ii, footprint.GetFPID().GetUniStringLibId(), "->", dst_libpath )