Skip to content

Instantly share code, notes, and snippets.

@mattcox
Created February 14, 2019 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattcox/bce19f7abbdfec0cf6b5b9ea222f8436 to your computer and use it in GitHub Desktop.
Save mattcox/bce19f7abbdfec0cf6b5b9ea222f8436 to your computer and use it in GitHub Desktop.
Demonstrates how to list the kits installed in Modo, and query the version numbers. This mostly is a wrapper for the kit.version command.
#python
'''
Demonstrates how to list the kits installed in Modo, and query the version
numbers. This mostly is a wrapper for the kit.version command.
'''
import lx
import lxifc
import lxu
SERVER_NAME = "kit.dump"
class KitList:
def __init__(self):
self.kits = []
'''
Spawn the kit.version command. SpawnFromString returns the
command as a tuple - we care about the third argument which is
the command object.
'''
command = lx.service.Command().SpawnFromString("kit.version")[2]
'''
Query the command for an AttributesUI interface, and read the
ValueHints for the first argument - the name argument.
'''
attributesUI = lx.object.AttributesUI(command)
valueHints = attributesUI.UIValueHints(0)
'''
Query the popup for the value hints object - this returns the
number of elements in the popup, and the name for each one.
We store the name, so we can use it to perform a lookup later.
'''
count = valueHints.PopCount()
for i in range(count):
self.kits.append(valueHints.PopInternalName(i))
def Count(self):
return len(self.kits)
def Name(self, index):
if len(self.kits) <= index:
raise IndexError()
return self.kits[index]
def Version(self, index):
if len(self.kits) <= index:
raise IndexError()
return lx.eval("kit.version name:{%s} version:?" % self.kits[index])
class Command(lxu.command.BasicCommand):
def __init__(self):
lxu.command.BasicCommand.__init__(self)
def cmd_Flags(self):
return 0
def basic_Execute(self, msg, flags):
kits = KitList()
count = kits.Count()
for i in range(count):
print "Name: {} - Version: {}".format(kits.Name(i), kits.Version(i))
lx.bless(Command, SERVER_NAME)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment