TclCommandExportGcode.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. from ObjectCollection import *
  2. from tclCommands.TclCommand import TclCommandSignaled
  3. class TclCommandExportGcode(TclCommandSignaled):
  4. """
  5. Tcl shell command to export gcode as tcl output for "set X [export_gcode ...]"
  6. Requires name to be available. It might still be in the
  7. making at the time this function is called, so check for
  8. promises and send to background if there are promises.
  9. This export may be captured and passed as preable
  10. to another "export_gcode" or "write_gcode" call to join G-Code.
  11. example:
  12. set_sys units MM
  13. new
  14. open_gerber tests/gerber_files/simple1.gbr -outname margin
  15. isolate margin -dia 3
  16. cncjob margin_iso
  17. cncjob margin_iso
  18. set EXPORT [export_gcode margin_iso_cnc]
  19. write_gcode margin_iso_cnc_1 /tmp/file.gcode ${EXPORT}
  20. """
  21. # array of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon)
  22. aliases = ['export_gcode']
  23. # dictionary of types from Tcl command, needs to be ordered
  24. arg_names = collections.OrderedDict([
  25. ('name', str),
  26. ('preamble', str),
  27. ('postamble', str)
  28. ])
  29. # dictionary of types from Tcl command, needs to be ordered , this is for options like -optionname value
  30. option_types = collections.OrderedDict()
  31. # array of mandatory options for current Tcl command: required = {'name','outname'}
  32. required = ['name']
  33. # structured help for current command, args needs to be ordered
  34. help = {
  35. 'main': "Export gcode into console output.",
  36. 'args': collections.OrderedDict([
  37. ('name', 'Name of the source Geometry object.'),
  38. ('preamble', 'Prepend GCODE.'),
  39. ('postamble', 'Append GCODE.')
  40. ]),
  41. 'examples': []
  42. }
  43. def execute(self, args, unnamed_args):
  44. """
  45. execute current TCL shell command
  46. :param args: array of known named arguments and options
  47. :param unnamed_args: array of other values which were passed into command
  48. without -somename and we do not have them in known arg_names
  49. :return: None or exception
  50. """
  51. name = args['name']
  52. obj = self.app.collection.get_by_name(name)
  53. if obj is None:
  54. self.raise_tcl_error("Object not found: %s" % name)
  55. if not isinstance(obj, CNCjob):
  56. self.raise_tcl_error('Expected CNCjob, got %s %s.' % (name, type(obj)))
  57. if self.app.collection.has_promises():
  58. self.raise_tcl_error('!!!Promises exists, but should not here!!!')
  59. del args['name']
  60. return obj.get_gcode(**args)