TclCommandJoinGeometry.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. from tclCommands.TclCommand import TclCommand
  2. from FlatCAMObj import FlatCAMGeometry
  3. import collections
  4. class TclCommandJoinGeometry(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_geometries', 'join_geometry']
  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.",
  23. 'args': collections.OrderedDict([
  24. ('outname', 'Name of the new Geometry Object.'),
  25. ('obj_name_0', 'Name of the first object'),
  26. ('obj_name_1', 'Name of the second object.'),
  27. ('obj_name_2...', 'Additional object names')
  28. ]),
  29. 'examples': []
  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. FlatCAMGeometry.merge(objs, obj_)
  48. if objs is not None:
  49. self.app.new_object("geometry", outname, initialize, plot=False)