TclCommandJoinExcellon.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. from tclCommands.TclCommand import *
  2. class TclCommandJoinExcellon(TclCommand):
  3. """
  4. Tcl shell command to merge Excellon objects.
  5. example:
  6. """
  7. # List of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon)
  8. aliases = ['join_excellon', 'join_excellons']
  9. # Dictionary of types from Tcl command, needs to be ordered
  10. arg_names = collections.OrderedDict([
  11. ('outname', str),
  12. ])
  13. # Dictionary of types from Tcl command, needs to be ordered , this is for options like -optionname value
  14. option_types = collections.OrderedDict([
  15. ])
  16. # array of mandatory options for current Tcl command: required = {'name','outname'}
  17. required = ['outname']
  18. # structured help for current command, args needs to be ordered
  19. help = {
  20. 'main': "Runs a merge operation (join) on the Excellon objects.",
  21. 'args': collections.OrderedDict([
  22. ('name', 'Name of the new Excellon Object.'),
  23. ('obj_name_0', 'Name of the first object'),
  24. ('obj_name_1', 'Name of the second object.'),
  25. ('obj_name_2...', 'Additional object names')
  26. ]),
  27. 'examples': []
  28. }
  29. def execute(self, args, unnamed_args):
  30. """
  31. :param args:
  32. :param unnamed_args:
  33. :return:
  34. """
  35. outname = args['name']
  36. obj_names = unnamed_args
  37. objs = []
  38. for obj_n in obj_names:
  39. obj = self.app.collection.get_by_name(str(obj_n))
  40. if obj is None:
  41. return "Object not found: %s" % obj_n
  42. else:
  43. objs.append(obj)
  44. def initialize(obj_, app):
  45. FlatCAMExcellon.merge(objs, obj_)
  46. if objs is not None:
  47. self.app.new_object("excellon", outname, initialize)