Find the model elements materials

Discussions concerning programming of SOFTIMAGE©
Gemini7
Posts: 14
Joined: 14 Oct 2012, 20:09
Skype: gemini4147

Find the model elements materials

Post by Gemini7 » 14 Oct 2012, 20:16

Hi All,
What can be the fastest way to find the a model elements ( it's children )
materials. Is there a xsi build-in command for it ?

Thansks !
G

User avatar
csaez
Posts: 253
Joined: 09 Jul 2012, 13:31
Skype: csaezmargotta
Location: Sydney, Australia

Re: Find the model elements materials

Post by csaez » 14 Oct 2012, 21:04

I don't know if exist a builtin command but maybe is fast enough iterate over the materials instead of model's children (there're usually more geometry objs than materials so...) and check if it's used.

Something like this...

Code: Select all

from sipyutils import si
si = si()


def GetMaterialOnModel(p_oModel):
    lChildren = p_oModel.FindChildren2("*").GetAsText()
    lMats = list()
    for oLib in si.ActiveProject.ActiveScene.MaterialLibraries:
        for oMat in oLib.Items:
            for oObj in oMat.UsedBy:
                if oObj.FullName in lChildren:
                    lMats.append(oMat)
    return lMats

for i in GetMaterialOnModel(si.Selection(0)):
    print i
Hope this help,
Cheers!

Gemini7
Posts: 14
Joined: 14 Oct 2012, 20:09
Skype: gemini4147

Re: Find the model elements materials

Post by Gemini7 » 15 Oct 2012, 09:08

Thanks !
I thought something similar like that.
Maybe i will need a faster code than iterate trough so long..
You know there could be nested models and a lot of materials and
the time it requires can be very long.

Thank you again.
G