From c439009251c0eb9f33c1566106e3a76394ee722e Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Mon, 2 Dec 2019 20:54:18 +0200 Subject: [PATCH] - added 3 new tcl commands: export dxf, export excellon and export gerber --- FlatCAMApp.py | 10 ++++- FlatCAMObj.py | 2 +- README.md | 1 + tclCommands/TclCommandExportDXF.py | 49 +++++++++++++++++++++++++ tclCommands/TclCommandExportExcellon.py | 49 +++++++++++++++++++++++++ tclCommands/TclCommandExportGerber.py | 49 +++++++++++++++++++++++++ tclCommands/__init__.py | 3 ++ 7 files changed, 160 insertions(+), 3 deletions(-) create mode 100644 tclCommands/TclCommandExportDXF.py create mode 100644 tclCommands/TclCommandExportExcellon.py create mode 100644 tclCommands/TclCommandExportGerber.py diff --git a/FlatCAMApp.py b/FlatCAMApp.py index 2538919f..3223335a 100644 --- a/FlatCAMApp.py +++ b/FlatCAMApp.py @@ -2097,7 +2097,8 @@ class App(QtCore.QObject): # ##################################################################################### self.tcl_commands_list = ['add_circle', 'add_poly', 'add_polygon', 'add_polyline', 'add_rectangle', 'aligndrill', 'aligndrillgrid', 'bbox', 'bounding_box', 'clear', 'cncjob', 'cutout', - 'delete', 'drillcncjob', 'export_gcode', 'export_svg', 'ext', 'exteriors', 'follow', + 'delete', 'drillcncjob', 'export_dxf', 'edxf', 'export_excellon', 'ee', 'export_exc', + 'export_gcode', 'export_gerber', 'egr', 'export_svg', 'ext', 'exteriors', 'follow', 'geo_union', 'geocutout', 'get_names', 'get_sys', 'getsys', 'help', 'import_svg', 'interiors', 'isolate', 'join_excellon', 'join_excellons', 'join_geometries', 'join_geometry', 'list_sys', 'listsys', 'milld', 'mills', 'milldrills', 'millslots', @@ -10131,7 +10132,7 @@ class App(QtCore.QObject): self.report_usage("export_excellon()") if filename is None: - filename = self.defaults["global_last_save_folder"] + filename = self.defaults["global_last_save_folder"] + '/' + 'exported_excellon' self.log.debug("export_excellon()") @@ -10148,6 +10149,11 @@ class App(QtCore.QObject): else: obj = local_use + if not isinstance(obj, FlatCAMExcellon): + self.inform.emit('[ERROR_NOTCL] %s' % + _("Failed. Only Excellon objects can be saved as Excellon files...")) + return + # updated units eunits = self.defaults["excellon_exp_units"] ewhole = self.defaults["excellon_exp_integer"] diff --git a/FlatCAMObj.py b/FlatCAMObj.py index 80b2c6af..49fedddc 100644 --- a/FlatCAMObj.py +++ b/FlatCAMObj.py @@ -2334,7 +2334,7 @@ class FlatCAMExcellon(FlatCAMObj, Excellon): def build_ui(self): FlatCAMObj.build_ui(self) - self.units = self.app.udefaults['units'].upper() + self.units = self.app.defaults['units'].upper() try: # if connected, disconnect the signal from the slot on item_changed as it creates issues diff --git a/README.md b/README.md index 847090de..9faa0475 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ CAD program, and create G-Code for Isolation routing. - fixed issue #343; updated the Image Tool - improvements in Importing SVG as Gerber - added an automatic source generation (it is not infallible) - a hack to import correctly the QRCode exported as SVG from FlatCAM +- added 3 new tcl commands: export dxf, export excellon and export gerber 28.11.2019 diff --git a/tclCommands/TclCommandExportDXF.py b/tclCommands/TclCommandExportDXF.py new file mode 100644 index 00000000..58aab483 --- /dev/null +++ b/tclCommands/TclCommandExportDXF.py @@ -0,0 +1,49 @@ +from tclCommands.TclCommand import TclCommand + +import collections + + +class TclCommandExportDXF(TclCommand): + """ + Tcl shell command to export a Geometry Object as an DXF File. + + example: + export_dxf path/my_geometry filename + """ + + # List of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon) + aliases = ['export_dxf', 'edxf'] + + # Dictionary of types from Tcl command, needs to be ordered + arg_names = collections.OrderedDict([ + ('obj_name', str), + ('filename', str) + ]) + + # Dictionary of types from Tcl command, needs to be ordered , this is for options like -optionname value + option_types = collections.OrderedDict([ + ]) + + # array of mandatory options for current Tcl command: required = ['name','outname'] + required = ['obj_name'] + + # structured help for current command, args needs to be ordered + help = { + 'main': "Export a Geometry Object as a DXF File.", + 'args': collections.OrderedDict([ + ('obj_name', 'Name of the object to export.'), + ('filename', 'Path to the file to export.') + ]), + 'examples': ['export_dxf my_geo path/my_file.dxf'] + } + + def execute(self, args, unnamed_args): + """ + + :param args: + :param unnamed_args: + :return: + """ + if 'filename' not in args: + args['filename'] = self.app.defaults["global_last_save_folder"] + '/' + args['obj_name'] + self.app.export_dxf(use_thread=False,**args) diff --git a/tclCommands/TclCommandExportExcellon.py b/tclCommands/TclCommandExportExcellon.py new file mode 100644 index 00000000..36e6e24c --- /dev/null +++ b/tclCommands/TclCommandExportExcellon.py @@ -0,0 +1,49 @@ +from tclCommands.TclCommand import TclCommand + +import collections + + +class TclCommandExportExcellon(TclCommand): + """ + Tcl shell command to export a Excellon Object as an Excellon File. + + example: + export_exc path/my_excellon filename + """ + + # List of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon) + aliases = ['export_exc', 'ee', 'export_excellon'] + + # Dictionary of types from Tcl command, needs to be ordered + arg_names = collections.OrderedDict([ + ('obj_name', str), + ('filename', str) + ]) + + # Dictionary of types from Tcl command, needs to be ordered , this is for options like -optionname value + option_types = collections.OrderedDict([ + ]) + + # array of mandatory options for current Tcl command: required = ['name','outname'] + required = ['obj_name'] + + # structured help for current command, args needs to be ordered + help = { + 'main': "Export a Excellon Object as a Excellon File.", + 'args': collections.OrderedDict([ + ('obj_name', 'Name of the object to export.'), + ('filename', 'Path to the file to export.') + ]), + 'examples': ['export_excellon my_excellon path/my_file.drl'] + } + + def execute(self, args, unnamed_args): + """ + + :param args: + :param unnamed_args: + :return: + """ + if 'filename' not in args: + args['filename'] = self.app.defaults["global_last_save_folder"] + '/' + args['obj_name'] + self.app.export_excellon(use_thread=False,**args) diff --git a/tclCommands/TclCommandExportGerber.py b/tclCommands/TclCommandExportGerber.py new file mode 100644 index 00000000..a4d27152 --- /dev/null +++ b/tclCommands/TclCommandExportGerber.py @@ -0,0 +1,49 @@ +from tclCommands.TclCommand import TclCommand + +import collections + + +class TclCommandExportGerber(TclCommand): + """ + Tcl shell command to export a Gerber Object as an Gerber File. + + example: + export_exc path/my_excellon filename + """ + + # List of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon) + aliases = ['export_grb', 'egr', 'export_gerber'] + + # Dictionary of types from Tcl command, needs to be ordered + arg_names = collections.OrderedDict([ + ('obj_name', str), + ('filename', str) + ]) + + # Dictionary of types from Tcl command, needs to be ordered , this is for options like -optionname value + option_types = collections.OrderedDict([ + ]) + + # array of mandatory options for current Tcl command: required = ['name','outname'] + required = ['obj_name'] + + # structured help for current command, args needs to be ordered + help = { + 'main': "Export a Gerber Object as a Gerber File.", + 'args': collections.OrderedDict([ + ('obj_name', 'Name of the object to export.'), + ('filename', 'Path to the file to export.') + ]), + 'examples': ['export_gerber my_gerber path/my_file.gbr'] + } + + def execute(self, args, unnamed_args): + """ + + :param args: + :param unnamed_args: + :return: + """ + if 'filename' not in args: + args['filename'] = self.app.defaults["global_last_save_folder"] + '/' + args['obj_name'] + self.app.export_gerber(use_thread=False,**args) diff --git a/tclCommands/__init__.py b/tclCommands/__init__.py index 8295926f..a143eb30 100644 --- a/tclCommands/__init__.py +++ b/tclCommands/__init__.py @@ -17,6 +17,9 @@ import tclCommands.TclCommandCopperClear import tclCommands.TclCommandCutout import tclCommands.TclCommandDelete import tclCommands.TclCommandDrillcncjob +import tclCommands.TclCommandExportDXF +import tclCommands.TclCommandExportExcellon +import tclCommands.TclCommandExportGerber import tclCommands.TclCommandExportGcode import tclCommands.TclCommandExportSVG import tclCommands.TclCommandExteriors