TclCommandCncjob.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. from ObjectCollection import *
  2. import TclCommand
  3. class TclCommandCncjob(TclCommand.TclCommand):
  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. ('timeout', 'Max wait for job timeout before error.')
  46. ]),
  47. 'examples': []
  48. }
  49. def execute(self, args, unnamed_args):
  50. """
  51. execute current TCL shell command
  52. :param args: array of known named arguments and options
  53. :param unnamed_args: array of other values which were passed into command
  54. without -somename and we do not have them in known arg_names
  55. :return: None or exception
  56. """
  57. name = args['name']
  58. if 'outname' not in args:
  59. args['outname'] = name + "_cnc"
  60. if 'timeout' in args:
  61. timeout = args['timeout']
  62. else:
  63. timeout = 10000
  64. obj = self.app.collection.get_by_name(name)
  65. if obj is None:
  66. self.raise_tcl_error("Object not found: %s" % name)
  67. if not isinstance(obj, FlatCAMGeometry):
  68. self.raise_tcl_error('Expected FlatCAMGeometry, got %s %s.' % (name, type(obj)))
  69. del args['name']
  70. obj.generatecncjob(use_thread = False, **args)