Created
October 5, 2016 16:21
-
-
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.
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
# !/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