Get shape from material?


#1

I have an object in scene,this object has a shading group,and a material connect to this shading group.
Now I want to get shape of this object from material,how can I do that?


#2

You did not specify which programming language, so Iโ€™ve gone for pymel. It simply does what you already did, which is to follow the connections. So in this example I have a material called โ€œblinn1โ€ assigned to my objects.

import pymel.core as pm
material = pm.PyNode('blinn1')
shadingGroups = material.shadingGroups()
objects = []
for sg in shadingGroups:
    numDagSetMembers = sg.dagSetMembers.numElements()
    for i in range(numDagSetMembers):
        object = sg.dagSetMembers[i].connections()[0]
        objects.append(object)
print objects

David


#3

Many thanks. :thumbsup: