Created
January 27, 2014 09:58
-
-
Save nicelifeBS/8645940 to your computer and use it in GitHub Desktop.
modo script - select a material by its name
This file contains hidden or 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
#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