TclCommandMillHoles.py 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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', 'mill']
  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. ('use_threads', bool)
  22. ])
  23. # array of mandatory options for current Tcl command: required = {'name','outname'}
  24. required = ['name']
  25. # structured help for current command, args needs to be ordered
  26. help = {
  27. 'main': "Create Geometry Object for milling holes from Excellon.",
  28. 'args': collections.OrderedDict([
  29. ('name', 'Name of the Excellon Object.'),
  30. ('tools', 'Comma separated indexes of tools (example: 1,3 or 2).'),
  31. ('tooldia', 'Diameter of the milling tool (example: 0.1).'),
  32. ('outname', 'Name of object to create.'),
  33. ('use_thread', 'If to use multithreading: True or False.')
  34. ]),
  35. 'examples': ['millholes mydrills']
  36. }
  37. def execute(self, args, unnamed_args):
  38. """
  39. :param args: array of known named arguments and options
  40. :param unnamed_args: array of other values which were passed into command
  41. without -somename and we do not have them in known arg_names
  42. :return: None or exception
  43. """
  44. name = args['name']
  45. if 'outname' not in args:
  46. args['outname'] = name + "_mill"
  47. try:
  48. if 'tools' in args and args['tools'] != 'all':
  49. # Split and put back. We are passing the whole dictionary later.
  50. args['tools'] = [x.strip() for x in args['tools'].split(",")]
  51. else:
  52. args['tools'] = 'all'
  53. except Exception as e:
  54. self.raise_tcl_error("Bad tools: %s" % str(e))
  55. try:
  56. obj = self.app.collection.get_by_name(str(name))
  57. except:
  58. self.raise_tcl_error("Could not retrieve object: %s" % name)
  59. if not isinstance(obj, FlatCAMExcellon):
  60. self.raise_tcl_error('Only Excellon objects can be mill-drilled, got %s %s.' % (name, type(obj)))
  61. if self.app.collection.has_promises():
  62. self.raise_tcl_error('!!!Promises exists, but should not here!!!')
  63. try:
  64. # 'name' is not an argument of obj.generate_milling()
  65. del args['name']
  66. # This runs in the background... Is blocking handled?
  67. success, msg = obj.generate_milling_drills(**args)
  68. except Exception as e:
  69. self.raise_tcl_error("Operation failed: %s" % str(e))
  70. if not success:
  71. self.raise_tcl_error(msg)