TclCommandJoinExcellon.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. # Dictionary of types from Tcl command, needs to be ordered
  12. arg_names = collections.OrderedDict([
  13. ('outname', str),
  14. ])
  15. # Dictionary of types from Tcl command, needs to be ordered , this is for options like -optionname value
  16. option_types = collections.OrderedDict([
  17. ])
  18. # array of mandatory options for current Tcl command: required = {'name','outname'}
  19. required = ['outname']
  20. # structured help for current command, args needs to be ordered
  21. help = {
  22. 'main': "Runs a merge operation (join) on the Excellon objects.\n"
  23. "The names of the Excellon objects to be merged will be entered after the outname,\n"
  24. "separated by spaces. See the example bellow.\n"
  25. "WARNING: if the name of an Excellon objects has spaces, enclose the name with quotes.",
  26. 'args': collections.OrderedDict([
  27. ('outname', 'Name of the new Excellon Object made by joining of other Excellon objects. Required'),
  28. ]),
  29. 'examples': ['join_excellons merged_new_excellon exc_name_1 "exc name_2"']
  30. }
  31. def execute(self, args, unnamed_args):
  32. """
  33. :param args:
  34. :param unnamed_args:
  35. :return:
  36. """
  37. outname = args['outname']
  38. obj_names = unnamed_args
  39. objs = []
  40. for obj_n in obj_names:
  41. obj = self.app.collection.get_by_name(str(obj_n))
  42. if obj is None:
  43. return "Object not found: %s" % obj_n
  44. else:
  45. objs.append(obj)
  46. def initialize(obj_, app):
  47. FlatCAMExcellon.merge(self, objs, obj_)
  48. if objs:
  49. self.app.new_object("excellon", outname, initialize, plot=False)
  50. else:
  51. return "No Excellon objects to be joined."