Last active
December 30, 2015 08:39
-
-
Save mattcox/7804267 to your computer and use it in GitHub Desktop.
"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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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