Skip to content

Instantly share code, notes, and snippets.

@cecilemuller
Last active January 1, 2023 11:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cecilemuller/915098f9d94c80beda22a53f13dc837b to your computer and use it in GitHub Desktop.
Save cecilemuller/915098f9d94c80beda22a53f13dc837b to your computer and use it in GitHub Desktop.
Marmoset Toolbag: find material/object by name
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
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