Rename Item example

From The Foundry MODO SDK wiki
Revision as of 13:46, 30 March 2013 by Jangell (Talk | contribs)

Jump to: navigation, search

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.

import lx
import lxifc
import lxu.command
class ItemRenameCommand(lxu.command.BasicCommand):
    def __init__(self):
        self.dyna_Add('name', lx.symbol.sTYPE_STRING)
        self.basic_SetFlags(0, lx.symbol.fCMDARG_OPTIONAL)
    def basic_Execute(self, msg, flags):
        newItemName = self.dyna_String(0, "none")
        if newItemName != 'none':
            currentSelection =
            itemObject = currentSelection.current()[0]
            itemObject.SetName('%s' % newItemName)
lx.bless(ItemRenameCommand, "pl_item.rename")