Rename Item example¶
Renaming items
The code below creates a custom command that will rename the currently selected item if an arg is given or it will remain the same if nothing is passed to it.
‘’’note’’’: as a custom command, the python source file needs to be placed in an ‘lxserv’ folder in order to be ‘blessed’ (registered) as a plugin at startup.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #python
import lx
import lxifc
import lxu.command
import lxu.select
class ItemRenameCommand(lxu.command.BasicCommand):
def __init__(self):
lxu.command.BasicCommand.__init__(self)
self.dyna_Add('name', lx.symbol.sTYPE_STRING)
self.basic_SetFlags(0, lx.symbol.fCMDARG_OPTIONAL)
def cmd_Flags(self):
return lx.symbol.fCMD_MODEL | lx.symbol.fCMD_UNDO
def basic_Execute(self, msg, flags):
newItemName = self.dyna_String(0, "none")
if newItemName != 'none':
currentSelection = lxu.select.ItemSelection()
itemObject = currentSelection.current()[0]
itemObject.SetName('%s' % newItemName)
else:
pass
lx.bless(ItemRenameCommand, "pl_item.rename")
|