Support to mill all holes from the command line. Fixes #218.
This commit is contained in:
parent
626176a9a4
commit
62f0662083
@ -824,7 +824,7 @@ class FlatCAMExcellon(FlatCAMObj, Excellon):
|
||||
"""
|
||||
Note: This method is a good template for generic operations as
|
||||
it takes it's options from parameters or otherwise from the
|
||||
object's options and returns a success, msg tuple as feedback
|
||||
object's options and returns a (success, msg) tuple as feedback
|
||||
for shell operations.
|
||||
|
||||
:return: Success/failure condition tuple (bool, str).
|
||||
@ -842,6 +842,13 @@ class FlatCAMExcellon(FlatCAMObj, Excellon):
|
||||
if tooldia is None:
|
||||
tooldia = self.options["tooldia"]
|
||||
|
||||
# Sort tools by diameter. items() -> [('name', diameter), ...]
|
||||
sorted_tools = sorted(self.tools.items(), key=lambda tl: tl[1])
|
||||
|
||||
if tools == "all":
|
||||
tools = [i[0] for i in sorted_tools] # List if ordered tool names.
|
||||
log.debug("Tools 'all' and sorted are: %s" % str(tools))
|
||||
|
||||
if len(tools) == 0:
|
||||
self.app.inform.emit("Please select one or more tools from the list and try again.")
|
||||
return False, "Error: No tools."
|
||||
|
17
camlib.py
17
camlib.py
@ -2509,6 +2509,7 @@ class Excellon(Geometry):
|
||||
|
||||
Geometry.__init__(self)
|
||||
|
||||
# self.tools[name] = {"C": diameter<float>}
|
||||
self.tools = {}
|
||||
|
||||
self.drills = []
|
||||
@ -2958,6 +2959,10 @@ class CNCjob(Geometry):
|
||||
:type exobj: Excellon
|
||||
:param tools: Comma separated tool names
|
||||
:type: tools: str
|
||||
:param toolchange: Use tool change sequence between tools.
|
||||
:type toolchange: bool
|
||||
:param toolchangez: Height at which to perform the tool change.
|
||||
:type toolchangez: float
|
||||
:return: None
|
||||
:rtype: None
|
||||
"""
|
||||
@ -2966,15 +2971,15 @@ class CNCjob(Geometry):
|
||||
|
||||
# Tools
|
||||
|
||||
# sort the tools list by the second item in tuple (here we have a dict with diameter of the tool)
|
||||
# so we actually are sorting the tools by diameter
|
||||
sorted_tools = sorted(exobj.tools.items(), key = lambda x: x[1])
|
||||
# Sort tools by diameter. items() -> [('name', diameter), ...]
|
||||
sorted_tools = sorted(exobj.tools.items(), key=lambda tl: tl[1])
|
||||
|
||||
if tools == "all":
|
||||
tools = [i[0] for i in sorted_tools] # we get a array of ordered tools
|
||||
tools = [i[0] for i in sorted_tools] # List if ordered tool names.
|
||||
log.debug("Tools 'all' and sorted are: %s" % str(tools))
|
||||
else:
|
||||
selected_tools = [x.strip() for x in tools.split(",")] # we strip spaces and also separate the tools by ','
|
||||
selected_tools = filter(lambda i: i in selected_tools, selected_tools)
|
||||
selected_tools = [x.strip() for x in tools.split(",")]
|
||||
selected_tools = filter(lambda tl: tl in selected_tools, selected_tools)
|
||||
|
||||
# Create a sorted list of selected tools from the sorted_tools list
|
||||
tools = [i for i, j in sorted_tools for k in selected_tools if i == k]
|
||||
|
@ -11,8 +11,8 @@ class TclCommandExportGcode(TclCommand.TclCommandSignaled):
|
||||
promises and send to background if there are promises.
|
||||
|
||||
|
||||
this export may be catched by tcl and past as preable to another export_gcode or write_gcode
|
||||
this can be used to join GCODES
|
||||
This export may be captured and passed as preable
|
||||
to another "export_gcode" or "write_gcode" call to join G-Code.
|
||||
|
||||
example:
|
||||
set_sys units MM
|
||||
|
@ -15,15 +15,15 @@ class TclCommandMillHoles(TclCommand.TclCommandSignaled):
|
||||
|
||||
# Dictionary of types from Tcl command, needs to be ordered
|
||||
arg_names = collections.OrderedDict([
|
||||
('name', str),
|
||||
('tools', str),
|
||||
('tooldia', float),
|
||||
('outname', str)
|
||||
('name', str)
|
||||
])
|
||||
|
||||
# Dictionary of types from Tcl command, needs to be ordered , this is for options like -optionname value
|
||||
# Dictionary of types from Tcl command, needs to be ordered.
|
||||
# This is for options like -optionname value
|
||||
option_types = collections.OrderedDict([
|
||||
|
||||
('tools', str),
|
||||
('outname', str),
|
||||
('tooldia', float)
|
||||
])
|
||||
|
||||
# array of mandatory options for current Tcl command: required = {'name','outname'}
|
||||
@ -38,23 +38,29 @@ class TclCommandMillHoles(TclCommand.TclCommandSignaled):
|
||||
('tooldia', 'Diameter of the milling tool (example: 0.1).'),
|
||||
('outname', 'Name of object to create.')
|
||||
]),
|
||||
'examples': ['scale my_geometry 4.2']
|
||||
'examples': ['millholes mydrills']
|
||||
}
|
||||
|
||||
def execute(self, args, unnamed_args):
|
||||
"""
|
||||
|
||||
:param args:
|
||||
:param unnamed_args:
|
||||
:return:
|
||||
:param args: array of known named arguments and options
|
||||
:param unnamed_args: array of other values which were passed into command
|
||||
without -somename and we do not have them in known arg_names
|
||||
:return: None or exception
|
||||
"""
|
||||
|
||||
name = args['name']
|
||||
|
||||
if 'outname' not in args:
|
||||
args['outname'] = name + "_mill"
|
||||
|
||||
try:
|
||||
if 'tools' in args:
|
||||
if 'tools' in args and args['tools'] != 'all':
|
||||
# Split and put back. We are passing the whole dictionary later.
|
||||
args['tools'] = [x.strip() for x in args['tools'].split(",")]
|
||||
else:
|
||||
args['tools'] = 'all'
|
||||
except Exception as e:
|
||||
self.raise_tcl_error("Bad tools: %s" % str(e))
|
||||
|
||||
@ -67,6 +73,9 @@ class TclCommandMillHoles(TclCommand.TclCommandSignaled):
|
||||
self.raise_tcl_error('Only Excellon objects can be mill-drilled, got %s %s.' % (name, type(obj)))
|
||||
|
||||
try:
|
||||
# 'name' is not an argument of obj.generate_milling()
|
||||
del args['name']
|
||||
|
||||
# This runs in the background... Is blocking handled?
|
||||
success, msg = obj.generate_milling(**args)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user