TclCommandDelete.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. from tclCommands.TclCommand import *
  2. class TclCommandDelete(TclCommand):
  3. """
  4. Tcl shell command to delete an object.
  5. example:
  6. """
  7. # List of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon)
  8. aliases = ['delete']
  9. # Dictionary of types from Tcl command, needs to be ordered
  10. arg_names = collections.OrderedDict([
  11. ('name', 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 = ['name']
  18. # structured help for current command, args needs to be ordered
  19. help = {
  20. 'main': 'Deletes the given object.',
  21. 'args': collections.OrderedDict([
  22. ('name', 'Name of the Object.'),
  23. ]),
  24. 'examples': []
  25. }
  26. def execute(self, args, unnamed_args):
  27. """
  28. :param args:
  29. :param unnamed_args:
  30. :return:
  31. """
  32. obj_name = args['name']
  33. try:
  34. # deselect all to avoid delete selected object when run delete from shell
  35. self.app.collection.set_all_inactive()
  36. self.app.collection.set_active(str(obj_name))
  37. self.app.on_delete() # Todo: This is an event handler for the GUI... bad?
  38. except Exception as e:
  39. return "Command failed: %s" % str(e)