Last active
January 1, 2023 11:54
-
-
Save cecilemuller/915098f9d94c80beda22a53f13dc837b to your computer and use it in GitHub Desktop.
Marmoset Toolbag: find material/object by 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
import mset | |
# Smarter "findMaterial": doesn't print a message in the console | |
# or throw an error when the object to find doesn't exist. | |
def getMaterial(name, createIfNotFound=False): | |
found = None | |
objs = mset.getAllMaterials() | |
for obj in objs: | |
if obj.name == name: | |
found = obj | |
break; | |
if createIfNotFound and (found == None): | |
found = mset.Material(name=name) | |
return found |
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
import mset | |
# Smarter "findObject" / "findInChildren": doesn't print a message in the console | |
# or throw an error when the object to find doesn't exist. | |
def getObject(name, parent=None): | |
found = None | |
if parent == None: | |
objs = mset.getAllObjects() | |
else: | |
objs = parent.getChildren() | |
for obj in objs: | |
if obj.name == name: | |
found = obj | |
break; | |
return found |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment