Skip to content

Instantly share code, notes, and snippets.

@ivogrig
Created July 24, 2015 11:31
Show Gist options
  • Save ivogrig/4c3c3dfc21b1f9eeb1ca to your computer and use it in GitHub Desktop.
Save ivogrig/4c3c3dfc21b1f9eeb1ca to your computer and use it in GitHub Desktop.
Example of finding materials connected to a mesh. This should become redundant as there will be convenience functions added to the TD SDK soon.
# Example of finding materials connected to a mesh. This should become redundant as
# there will be convenience functions added to the TD SDK soon.
import modo
# This gets the selected mesh if any
mesh = modo.Mesh()
if mesh:
# First collect the materials polygon tags of the mesh in question
ptags = set()
for tagType in (lx.symbol.i_POLYTAG_MATERIAL, lx.symbol.i_POLYTAG_PART):
for index in range(mesh.geometry.PTagCount(tagType)):
ptag = mesh.geometry.internalMesh.PTagByIndex(tagType, index)
ptags.add(ptag)
# Then, iterate all group masks and see if their tags match with the ones from the mesh
groupMasks = set()
for groupMask in modo.Scene().renderItem.childrenByType('mask'):
tagType = groupMask.channel('ptyp').get()
if tagType in ('Material', 'Part'):
assignedTag = groupMask.channel('ptag').get()
if assignedTag in ptags:
groupMasks.add(groupMask)
# Print their names and children's names
for groupMask in groupMasks:
print ''
print 'groupMask {}:'.format(groupMask.name)
for child in groupMask.children():
print '- child {}'.format(child.name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment