TclCommandJoinExcellon.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. from tclCommands.TclCommand import TclCommand
  2. from FlatCAMObj import FlatCAMExcellon
  3. import collections
  4. class TclCommandJoinExcellon(TclCommand):
  5. """
  6. Tcl shell command to merge Excellon objects.
  7. example:
  8. """
  9. # List of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon)
  10. aliases = ['join_excellon', 'join_excellons']
  11. description = '%s %s' % ("--", "Merge two or more Excellon objects drills and create "
  12. "a new Excellon object with them.")
  13. # Dictionary of types from Tcl command, needs to be ordered
  14. arg_names = collections.OrderedDict([
  15. ('outname', str),
  16. ])
  17. # Dictionary of types from Tcl command, needs to be ordered , this is for options like -optionname value
  18. option_types = collections.OrderedDict([
  19. ])
  20. # array of mandatory options for current Tcl command: required = {'name','outname'}
  21. required = ['outname']
  22. # structured help for current command, args needs to be ordered
  23. help = {
  24. 'main': "Runs a merge operation (join) on the Excellon objects.\n"
  25. "The names of the Excellon objects to be merged will be entered after the outname,\n"
  26. "separated by spaces. See the example bellow.\n"
  27. "WARNING: if the name of an Excellon objects has spaces, enclose the name with quotes.",
  28. 'args': collections.OrderedDict([
  29. ('outname', 'Name of the new Excellon Object made by joining of other Excellon objects. Required'),
  30. ]),
  31. 'examples': ['join_excellons merged_new_excellon exc_name_1 "exc name_2"']
  32. }
  33. def execute(self, args, unnamed_args):
  34. """
  35. :param args:
  36. :param unnamed_args:
  37. :return:
  38. """
  39. outname = args['outname']
  40. obj_names = unnamed_args
  41. objs = []
  42. for obj_n in obj_names:
  43. obj = self.app.collection.get_by_name(str(obj_n))
  44. if obj is None:
  45. return "Object not found: %s" % obj_n
  46. else:
  47. objs.append(obj)
  48. def initialize(obj_, app):
  49. FlatCAMExcellon.merge(self, objs, obj_)
  50. if objs and len(objs) >= 2:
  51. self.app.new_object("excellon", outname, initialize, plot=False)
  52. else:
  53. return "No Excellon objects to be joined or less than two Excellon objects specified for merging."