Skip to content

Instantly share code, notes, and snippets.

@ivogrig
Last active May 7, 2016 07:22
Show Gist options
  • Save ivogrig/72307e61f8eedd38e386 to your computer and use it in GitHub Desktop.
Save ivogrig/72307e61f8eedd38e386 to your computer and use it in GitHub Desktop.
Example command to read or write item tags
"""Example command to read or write item tags
Example usage:
item.editTag sunLight013 TAGN "Test"
item.editTag sunLight013 TAGN ?
import modo
item = modo.Item('Directional Light')
value = 'Test'
# Set TAGN tag:
lx.eval('item.editTag item:%s tagName:TAGN tagValue:"%s"' % (item.id, value) )
# Query TAGN tag:
result = lx.eval('item.editTag item:%s tagName:TAGN tagValue:?' % item.id)
print result == value
"""
import lx
import lxifc
import lxu.command
import lxu.select
import modo
class CmdItemTag(lxu.command.BasicCommand):
def __init__(self):
lxu.command.BasicCommand.__init__(self)
self.dyna_Add('item', '&item')
self.dyna_Add('tagName', lx.symbol.sTYPE_STRING)
self.dyna_Add('tagValue', lx.symbol.sTYPE_STRING)
# Make this argument queryable
self.basic_SetFlags(2, lx.symbol.fCMDARG_QUERY)
def basic_Execute(self, msg, flags):
if not self.dyna_IsSet(0) or not self.dyna_IsSet(1):
return False
itemIdent = self.dyna_String(0, None)
tagName = self.dyna_String(1, None)
if not all( (itemIdent, tagName)):
return False
if self.dyna_IsSet(2):
tagValue = self.dyna_String(2, None)
if not tagValue:
return False
# Set tag value
modo.Item(itemIdent).setTag(tagName, tagValue)
def cmd_Query(self,index,vaQuery):
if not self.dyna_IsSet(0) or not self.dyna_IsSet(1):
return False
itemIdent = self.dyna_String(0, None)
tagName = self.dyna_String(1, None)
if not all( (itemIdent, tagName)):
return False
item = modo.Item(itemIdent)
tags = item.getTags()
if tagName in tags.keys():
# Read tag value
result = tags[tagName]
va = lx.object.ValueArray(vaQuery)
iptr = va.AddEmptyValue()
iptr.SetString(result)
return True
return False
lx.bless(CmdItemTag, "item.editTag")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment