Skip to content

Instantly share code, notes, and snippets.

@nicelifeBS
Created January 27, 2014 09:58
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 nicelifeBS/8645940 to your computer and use it in GitHub Desktop.
Save nicelifeBS/8645940 to your computer and use it in GitHub Desktop.
modo script - select a material by its name
#python
##--------------------------------------------##
#
# Author Bjoern Siegert 2014-01-27
#
# Slect a material by name if it is
# in the scene.
# Name is defined by an argument just after
# the script name
# (no {} or "" if spaces are in the name).
#
# E.g.: @selectMatByName.py material name
#
##--------------------------------------------##
## lx service and argument##
sceneService = lx.Service("sceneservice")
arg = lx.arg()
## select scene ##
sceneService.select("scene", "main")
# Get the number of items in the scene and
# walk through them. Save all ids of advancedMaterial items in a list
nItems = sceneService.query("item.N")
matIDs = {}
for item in xrange(nItems):
sceneService.select("item", str(item))
itemType = sceneService.query("item.type")
itemID = sceneService.query("item.id")
itemName = sceneService.query("item.name")
if itemType == "advancedMaterial":
matIDs[itemName] = itemID
# If the material with a given name via the argument is in
# the dictionary matIDs it is selected.
if arg in matIDs:
lx.out("Found following Material:", matIDs[arg])
lx.eval("select.subItem %s set textureLayer" %matIDs[arg])
else:
lx.out("Material not found")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment