TclCommandMillHoles.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. from tclCommands.TclCommand import *
  2. class TclCommandMillHoles(TclCommandSignaled):
  3. """
  4. Tcl shell command to Create Geometry Object for milling holes from Excellon.
  5. example:
  6. millholes my_drill -tools 1,2,3 -tooldia 0.1 -outname mill_holes_geo
  7. """
  8. # List of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon)
  9. aliases = ['millholes']
  10. # Dictionary of types from Tcl command, needs to be ordered
  11. arg_names = collections.OrderedDict([
  12. ('name', str)
  13. ])
  14. # Dictionary of types from Tcl command, needs to be ordered.
  15. # This is for options like -optionname value
  16. option_types = collections.OrderedDict([
  17. ('tools', str),
  18. ('outname', str),
  19. ('tooldia', float)
  20. ])
  21. # array of mandatory options for current Tcl command: required = {'name','outname'}
  22. required = ['name']
  23. # structured help for current command, args needs to be ordered
  24. help = {
  25. 'main': "Create Geometry Object for milling holes from Excellon.",
  26. 'args': collections.OrderedDict([
  27. ('name', 'Name of the Excellon Object.'),
  28. ('tools', 'Comma separated indexes of tools (example: 1,3 or 2).'),
  29. ('tooldia', 'Diameter of the milling tool (example: 0.1).'),
  30. ('outname', 'Name of object to create.')
  31. ]),
  32. 'examples': ['millholes mydrills']
  33. }
  34. def execute(self, args, unnamed_args):
  35. """
  36. :param args: array of known named arguments and options
  37. :param unnamed_args: array of other values which were passed into command
  38. without -somename and we do not have them in known arg_names
  39. :return: None or exception
  40. """
  41. name = args['name']
  42. if 'outname' not in args:
  43. args['outname'] = name + "_mill"
  44. try:
  45. if 'tools' in args and args['tools'] != 'all':
  46. # Split and put back. We are passing the whole dictionary later.
  47. args['tools'] = [x.strip() for x in args['tools'].split(",")]
  48. else:
  49. args['tools'] = 'all'
  50. except Exception as e:
  51. self.raise_tcl_error("Bad tools: %s" % str(e))
  52. try:
  53. obj = self.app.collection.get_by_name(str(name))
  54. except:
  55. self.raise_tcl_error("Could not retrieve object: %s" % name)
  56. if not isinstance(obj, FlatCAMExcellon):
  57. self.raise_tcl_error('Only Excellon objects can be mill-drilled, got %s %s.' % (name, type(obj)))
  58. try:
  59. # 'name' is not an argument of obj.generate_milling()
  60. del args['name']
  61. # This runs in the background... Is blocking handled?
  62. success, msg = obj.generate_milling(**args)
  63. except Exception as e:
  64. self.raise_tcl_error("Operation failed: %s" % str(e))
  65. if not success:
  66. self.raise_tcl_error(msg)