Skip to content

Instantly share code, notes, and snippets.

@mattcox
Last active Dec 30, 2015
Embed
What would you like to do?
"Hello World!" - Demonstrates the very basics needed for a command. This will print "Hello World!" to the event log. The command will only be enabled if an item is selected, if there is no selection, then the command will be disabled.
#python
'''
Hello World!
This example demonstrates the very basics needed for a command. Firing
the command prints "Hello World!" to the event log. The command includes
enable and disable states, controlled by the selection. If an item
is selected, the command will be enabled, if not, it won't be.
'''
import lx
import lxifc
import lxu.select
import lxu.command
SERVER_NAME = "hello.world"
class Command (lxu.command.BasicCommand):
def __init__ (self):
lxu.command.BasicCommand.__init__(self)
def cmd_Flags (self):
'''
This function sets the flags. These basically mean
that the command performs scene/model changes. In
other words, it makes changes that the user would
expect to be undoable. The Hello World command isn't
really changing the scene, but it won't hurt to
make it undoable.
'''
return lx.symbol.fCMD_MODEL | lx.symbol.fCMD_UNDO
def basic_Enable (self, msg):
'''
The enable function is used to set the enable/disable
state of the command. Returning true makes the command
enabled and returning false makes the command disabled.
'''
if len (lxu.select.ItemSelection ().current ()) > 0:
return True
else:
return False
def basic_Execute (self, msg, flags):
'''
As the name suggests, the execute method is called
when the command is executed. We can at this point get
the value of any arguments and do what we need to do.
Success or failure is handled through an ILxMessage
object which can be initialized using the second
argument to the function.
'''
lx.out ("Hello World!")
'''
Bless the class, initializing the server.
'''
lx.bless (Command, SERVER_NAME)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment