TclCommandMillHoles.py 2.9 KB

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