Created
September 27, 2018 11:14
-
-
Save JFlynnXYZ/8959d6fc8be814e86fce08175aa42da6 to your computer and use it in GitHub Desktop.
This file contains 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 pymel.core as pm | |
def get_mat_assigned_for_obj(mat, obj): | |
if issubclass(type(mat), (str, unicode)): | |
mat = pm.PyNode(mat) | |
if issubclass(type(obj), (str, unicode)): | |
obj = pm.PyNode(obj) | |
members = mat.connections(type=pm.nt.ShadingEngine)[0].members() | |
obj_typ = type(obj) | |
if issubclass(obj_typ, pm.nt.Transform): | |
shp = obj.getShape() | |
elif issubclass(obj_typ, pm.nt.Mesh): | |
shp = obj | |
else: | |
raise ValueError("Invalid object! needs to be a Transform or Mesh") | |
mat_ass_objs = [] | |
for m in members: | |
m_type = type(m) | |
if issubclass(m_type, pm.Component): | |
if m.node() == shp: | |
mat_ass_objs.append(m) | |
elif issubclass(m_type, pm.nt.Mesh): | |
if m == shp: | |
mat_ass_objs.append(m) | |
return mat_ass_objs | |
if __name__ == "__main__": | |
pm.select(get_mat_assigned_for_obj(u"TEST", u"pTorus1"), replace=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment