TclCommandDrillcncjob.py 3.2 KB

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