From 4b28d980fd31e6c411feb81dbec6ea0a5841a2c9 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Mon, 16 Sep 2019 04:10:02 +0300 Subject: [PATCH 1/2] - fixed the App.on_view_source() method for CNCJob objects: the Gcode will now contain the Prepend and Append code from the Edit -> Preferences -> CNCJob -> CNCJob Options --- FlatCAMApp.py | 5 ++++- README.md | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/FlatCAMApp.py b/FlatCAMApp.py index f15284ac..d31f44ae 100644 --- a/FlatCAMApp.py +++ b/FlatCAMApp.py @@ -8240,7 +8240,10 @@ class App(QtCore.QObject): # then append the text from GCode to the text editor if obj.kind == 'cncjob': try: - file = obj.export_gcode(preamble='', postamble='', to_file=True) + file = obj.export_gcode( + preamble=self.defaults["cncjob_prepend"], + postamble=self.defaults["cncjob_append"], + to_file=True) if file == 'fail': return 'fail' except AttributeError: diff --git a/README.md b/README.md index cc7e8955..cce89d1f 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ CAD program, and create G-Code for Isolation routing. 16.09.2019 - modified the TclCommand New so it will no longer close all tabs when called (it closed the Code Editor tab which may have been holding the code that run) +- fixed the App.on_view_source() method for CNCJob objects: the Gcode will now contain the Prepend and Append code from the Edit -> Preferences -> CNCJob -> CNCJob Options 15.09.2019 From e9751e41b850af6fa4233ac846feb312fb10175d Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Mon, 16 Sep 2019 04:23:16 +0300 Subject: [PATCH 2/2] - added a new parameter named 'muted' for the TclCommands: cncjob, drillcncjob and write_gcode. Setting it as -muted 1 will disable the error reporting in TCL Shell --- README.md | 1 + tclCommands/TclCommandCncjob.py | 26 ++++++++++++++++++++------ tclCommands/TclCommandDrillcncjob.py | 21 ++++++++++++++++----- tclCommands/TclCommandWriteGCode.py | 20 ++++++++++++++++---- 4 files changed, 53 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index cce89d1f..df64688c 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ CAD program, and create G-Code for Isolation routing. - modified the TclCommand New so it will no longer close all tabs when called (it closed the Code Editor tab which may have been holding the code that run) - fixed the App.on_view_source() method for CNCJob objects: the Gcode will now contain the Prepend and Append code from the Edit -> Preferences -> CNCJob -> CNCJob Options +- added a new parameter named 'muted' for the TclCommands: cncjob, drillcncjob and write_gcode. Setting it as -muted 1 will disable the error reporting in TCL Shell 15.09.2019 diff --git a/tclCommands/TclCommandCncjob.py b/tclCommands/TclCommandCncjob.py index 46c2ef6d..bc7ff6aa 100644 --- a/tclCommands/TclCommandCncjob.py +++ b/tclCommands/TclCommandCncjob.py @@ -42,6 +42,7 @@ class TclCommandCncjob(TclCommandSignaled): ('dwell', bool), ('dwelltime', float), ('pp', str), + ('muted', int), ('outname', str) ]) @@ -71,7 +72,8 @@ class TclCommandCncjob(TclCommandSignaled): ('dwell', 'True or False; use (or not) the dwell'), ('dwelltime', 'Time to pause to allow the spindle to reach the full speed'), ('outname', 'Name of the resulting Geometry object.'), - ('pp', 'Name of the Geometry postprocessor. No quotes, case sensitive') + ('pp', 'Name of the Geometry postprocessor. No quotes, case sensitive'), + ('muted', 'It will not put errors in the Shell.') ]), 'examples': ['cncjob geo_name -tooldia 0.5 -z_cut -1.7 -z_move 2 -feedrate 120 -ppname_g default'] } @@ -91,13 +93,22 @@ class TclCommandCncjob(TclCommandSignaled): if 'outname' not in args: args['outname'] = str(name) + "_cnc" + if 'muted' in args: + muted = args['muted'] + obj = self.app.collection.get_by_name(str(name), isCaseSensitive=False) if obj is None: - self.raise_tcl_error("Object not found: %s" % str(name)) + if not muted: + self.raise_tcl_error("Object not found: %s" % str(name)) + else: + return if not isinstance(obj, FlatCAMGeometry): - self.raise_tcl_error('Expected FlatCAMGeometry, got %s %s.' % (str(name), type(obj))) + if not muted: + self.raise_tcl_error('Expected FlatCAMGeometry, got %s %s.' % (str(name), type(obj))) + else: + return args["tooldia"] = args["tooldia"] if "tooldia" in args else obj.options["cnctooldia"] @@ -134,9 +145,12 @@ class TclCommandCncjob(TclCommandSignaled): continue else: if args[arg] is None: - self.raise_tcl_error('One of the command parameters that have to be not None, is None.\n' - 'The parameter that is None is in the default values found in the list \n' - 'generated by the TclCommand "list_sys geom". or in the arguments.') + if not muted: + self.raise_tcl_error('One of the command parameters that have to be not None, is None.\n' + 'The parameter that is None is in the default values found in the list \n' + 'generated by the TclCommand "list_sys geom". or in the arguments.') + else: + return # HACK !!! Should be solved elsewhere!!! # default option for multidepth is False diff --git a/tclCommands/TclCommandDrillcncjob.py b/tclCommands/TclCommandDrillcncjob.py index 96632ec6..d8747ce9 100644 --- a/tclCommands/TclCommandDrillcncjob.py +++ b/tclCommands/TclCommandDrillcncjob.py @@ -31,7 +31,8 @@ class TclCommandDrillcncjob(TclCommandSignaled): ('pp', str), ('outname', str), ('opt_type', str), - ('diatol', float) + ('diatol', float), + ('muted', int) ]) # array of mandatory options for current Tcl command: required = {'name','outname'} @@ -62,7 +63,8 @@ class TclCommandDrillcncjob(TclCommandSignaled): 'the same as the ones in the tools from the Excellon object. E.g: if in drill_dias we have a ' 'diameter with value 1.0, in the Excellon we have a tool with dia = 1.05 and we set a tolerance ' 'diatol = 5.0 then the drills with the dia = (0.95 ... 1.05) ' - 'in Excellon will be processed. Float number.') + 'in Excellon will be processed. Float number.'), + ('muted', 'It will not put errors in the Shell or status bar.') ]), 'examples': ['drillcncjob test.TXT -drillz -1.5 -travelz 14 -feedrate 222 -feedrate_rapid 456 -spindlespeed 777' ' -toolchange True -toolchangez 33 -endz 22 -pp default\n' @@ -84,12 +86,18 @@ class TclCommandDrillcncjob(TclCommandSignaled): if 'outname' not in args: args['outname'] = name + "_cnc" + if 'muted' in args: + muted = args['muted'] + obj = self.app.collection.get_by_name(name) if obj is None: self.raise_tcl_error("Object not found: %s" % name) if not isinstance(obj, FlatCAMExcellon): - self.raise_tcl_error('Expected FlatCAMExcellon, got %s %s.' % (name, type(obj))) + if not muted: + self.raise_tcl_error('Expected FlatCAMExcellon, got %s %s.' % (name, type(obj))) + else: + return xmin = obj.options['xmin'] ymin = obj.options['ymin'] @@ -127,8 +135,11 @@ class TclCommandDrillcncjob(TclCommandSignaled): nr_diameters -= 1 if nr_diameters > 0: - self.raise_tcl_error("One or more tool diameters of the drills to be drilled passed to the " - "TclCommand are not actual tool diameters in the Excellon object.") + if not muted: + self.raise_tcl_error("One or more tool diameters of the drills to be drilled passed to the " + "TclCommand are not actual tool diameters in the Excellon object.") + else: + return # make a string of diameters separated by comma; this is what generate_from_excellon_by_tool() is # expecting as tools parameter diff --git a/tclCommands/TclCommandWriteGCode.py b/tclCommands/TclCommandWriteGCode.py index d1b1c9d4..98ce7cff 100644 --- a/tclCommands/TclCommandWriteGCode.py +++ b/tclCommands/TclCommandWriteGCode.py @@ -22,7 +22,8 @@ class TclCommandWriteGCode(TclCommandSignaled): # For options like -optionname value option_types = collections.OrderedDict([ ('preamble', str), - ('postamble', str) + ('postamble', str), + ('muted', int) ]) # array of mandatory options for current Tcl command: required = {'name','outname'} @@ -35,7 +36,9 @@ class TclCommandWriteGCode(TclCommandSignaled): ('name', 'Source CNC Job object.'), ('filename', 'Output filename.'), ('preamble', 'Text to append at the beginning.'), - ('postamble', 'Text to append at the end.') + ('postamble', 'Text to append at the end.'), + ('muted', 'It will not put errors in the Shell or status bar.') + ]), 'examples': ["write_gcode name c:\\\\gcode_repo"] } @@ -62,6 +65,9 @@ class TclCommandWriteGCode(TclCommandSignaled): preamble = args['preamble'] if 'preamble' in args else '' postamble = args['postamble'] if 'postamble' in args else '' + if 'muted' in args: + muted = args['muted'] + # TODO: This is not needed any more? All targets should be present. # If there are promised objects, wait until all promises have been fulfilled. # if self.collection.has_promises(): @@ -82,9 +88,15 @@ class TclCommandWriteGCode(TclCommandSignaled): try: obj = self.app.collection.get_by_name(str(obj_name)) except: - return "Could not retrieve object: %s" % obj_name + if not muted: + return "Could not retrieve object: %s" % obj_name + else: + return try: obj.export_gcode(str(filename), str(preamble), str(postamble)) except Exception as e: - return "Operation failed: %s" % str(e) + if not muted: + return "Operation failed: %s" % str(e) + else: + return