Skip to content

Instantly share code, notes, and snippets.

@MineClever
Forked from cecilemuller/getMaterial.py
Created January 1, 2023 11:54
Show Gist options
  • Save MineClever/0abd4d7aff80a74074cccf76d4cde476 to your computer and use it in GitHub Desktop.
Save MineClever/0abd4d7aff80a74074cccf76d4cde476 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