TclCommandCncjob.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. from tclCommands.TclCommand import *
  2. class TclCommandCncjob(TclCommandSignaled):
  3. """
  4. Tcl shell command to Generates a CNC Job from a Geometry Object.
  5. example:
  6. set_sys units MM
  7. new
  8. open_gerber tests/gerber_files/simple1.gbr -outname margin
  9. isolate margin -dia 3
  10. cncjob margin_iso
  11. """
  12. # array of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon)
  13. aliases = ['cncjob']
  14. # dictionary of types from Tcl command, needs to be ordered
  15. arg_names = collections.OrderedDict([
  16. ('name', str)
  17. ])
  18. # dictionary of types from Tcl command, needs to be ordered , this is for options like -optionname value
  19. option_types = collections.OrderedDict([
  20. ('z_cut', float),
  21. ('z_move', float),
  22. ('feedrate', float),
  23. ('tooldia', float),
  24. ('spindlespeed', int),
  25. ('multidepth', bool),
  26. ('depthperpass', float),
  27. ('outname', str)
  28. ])
  29. # array of mandatory options for current Tcl command: required = {'name','outname'}
  30. required = ['name']
  31. # structured help for current command, args needs to be ordered
  32. help = {
  33. 'main': "Generates a CNC Job from a Geometry Object.",
  34. 'args': collections.OrderedDict([
  35. ('name', 'Name of the source object.'),
  36. ('z_cut', 'Z-axis cutting position.'),
  37. ('z_move', 'Z-axis moving position.'),
  38. ('feedrate', 'Moving speed when cutting.'),
  39. ('tooldia', 'Tool diameter to show on screen.'),
  40. ('spindlespeed', 'Speed of the spindle in rpm (example: 4000).'),
  41. ('multidepth', 'Use or not multidepth cnccut.'),
  42. ('depthperpass', 'Height of one layer for multidepth.'),
  43. ('outname', 'Name of the resulting Geometry object.')
  44. ]),
  45. 'examples': []
  46. }
  47. def execute(self, args, unnamed_args):
  48. """
  49. execute current TCL shell command
  50. :param args: array of known named arguments and options
  51. :param unnamed_args: array of other values which were passed into command
  52. without -somename and we do not have them in known arg_names
  53. :return: None or exception
  54. """
  55. name = args['name']
  56. if 'outname' not in args:
  57. args['outname'] = name + "_cnc"
  58. obj = self.app.collection.get_by_name(name)
  59. if obj is None:
  60. self.raise_tcl_error("Object not found: %s" % name)
  61. if not isinstance(obj, FlatCAMGeometry):
  62. self.raise_tcl_error('Expected FlatCAMGeometry, got %s %s.' % (name, type(obj)))
  63. del args['name']
  64. obj.generatecncjob(use_thread=False, **args)