TclCommandDrillcncjob.py 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. from ObjectCollection import *
  2. from tclCommands.TclCommand import TclCommandSignaled
  3. class TclCommandDrillcncjob(TclCommandSignaled):
  4. """
  5. Tcl shell command to Generates a Drill CNC Job from a Excellon Object.
  6. """
  7. # array of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon)
  8. aliases = ['drillcncjob']
  9. # dictionary of types from Tcl command, needs to be ordered
  10. arg_names = collections.OrderedDict([
  11. ('name', str)
  12. ])
  13. # dictionary of types from Tcl command, needs to be ordered , this is for options like -optionname value
  14. option_types = collections.OrderedDict([
  15. ('tools', str),
  16. ('drillz', float),
  17. ('travelz', float),
  18. ('feedrate', float),
  19. ('spindlespeed', int),
  20. ('toolchange', bool),
  21. ('outname', str)
  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': "Generates a Drill CNC Job from a Excellon Object.",
  28. 'args': collections.OrderedDict([
  29. ('name', 'Name of the source object.'),
  30. ('tools', 'Comma separated indexes of tools (example: 1,3 or 2) or select all if not specified.'),
  31. ('drillz', 'Drill depth into material (example: -2.0).'),
  32. ('travelz', 'Travel distance above material (example: 2.0).'),
  33. ('feedrate', 'Drilling feed rate.'),
  34. ('spindlespeed', 'Speed of the spindle in rpm (example: 4000).'),
  35. ('toolchange', 'Enable tool changes (example: True).'),
  36. ('outname', 'Name of the resulting Geometry object.')
  37. ]),
  38. 'examples': []
  39. }
  40. def execute(self, args, unnamed_args):
  41. """
  42. execute current TCL shell command
  43. :param args: array of known named arguments and options
  44. :param unnamed_args: array of other values which were passed into command
  45. without -somename and we do not have them in known arg_names
  46. :return: None or exception
  47. """
  48. name = args['name']
  49. if 'outname' not in args:
  50. args['outname'] = name + "_cnc"
  51. obj = self.app.collection.get_by_name(name)
  52. if obj is None:
  53. self.raise_tcl_error("Object not found: %s" % name)
  54. if not isinstance(obj, FlatCAMExcellon):
  55. self.raise_tcl_error('Expected FlatCAMExcellon, got %s %s.' % (name, type(obj)))
  56. def job_init(job_obj, app):
  57. job_obj.z_cut = args["drillz"] if "drillz" in args else obj.options["drillz"]
  58. job_obj.z_move = args["travelz"] if "travelz" in args else obj.options["travelz"]
  59. job_obj.feedrate = args["feedrate"] if "feedrate" in args else obj.options["feedrate"]
  60. job_obj.spindlespeed = args["spindlespeed"] if "spindlespeed" in args else None
  61. toolchange = True if "toolchange" in args and args["toolchange"] == 1 else False
  62. tools = args["tools"] if "tools" in args else 'all'
  63. job_obj.generate_from_excellon_by_tool(obj, tools, toolchange)
  64. job_obj.gcode_parse()
  65. job_obj.create_geometry()
  66. self.app.new_object("cncjob", args['outname'], job_init)