TclCommandCncjob.py 2.7 KB

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