Skip to content

Instantly share code, notes, and snippets.

@Farfarer
Created October 5, 2016 16:21
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 Farfarer/53bf98500412b4f0480a4e60b356d1cb to your computer and use it in GitHub Desktop.
Save Farfarer/53bf98500412b4f0480a4e60b356d1cb to your computer and use it in GitHub Desktop.
Set and get the value of a tag that's stored with the scene in MODO.
# !/usr/bin/env python
import lx
import lxu
import lxu.select
def setSceneTag (tagID, tagValue)
if isinstance (tagID, basestring):
if len (tagID) != 4:
lx.out('Tag ID must be 4 characters long!')
return
tagID = lxu.lxID4 (tagID)
tag = lx.object.StringTag ()
scene = lx.object.Scene (lxu.select.SceneSelection ().current ())
if scene is None:
lx.out('No current scene!')
return
scene_item = scene.AnyItemOfType (lx.service.Scene ().ItemTypeLookup (lx.symbol.sITYPE_SCENE))
if scene_item is None:
lx.out('No current scene item!')
return
tag.set (scene_item)
tag.Set (tagID, tagValue)
def getSceneTag (tagID)
if isinstance (tagID, basestring):
if len (tagID) != 4:
lx.out('Tag ID must be 4 characters long!')
return
tagID = lxu.lxID4 (tagID)
tag = lx.object.StringTag ()
scene = lx.object.Scene (lxu.select.SceneSelection ().current ())
if scene is None:
lx.out('No current scene!')
return None
scene_item = scene.AnyItemOfType (lx.service.Scene ().ItemTypeLookup (lx.symbol.sITYPE_SCENE))
if scene_item is None:
lx.out('No current scene item!')
return None
tag.set (scene_item)
try:
return tag.Get (tagID)
except:
return None
# Usage.
# getSceneTag returns None if there is no tag by that ID or if getting the tag otherwise fails.
# Tags are strings of 4 alpha characters - they are encoded into an int for querying, using lxu.lxID4()
setSceneTag ('MYTG', 'Hello, this is my tag value.')
print getSceneTag ('MYTG')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment