Jump to content
nilsoncardososa

get list of materials

Recommended Posts

Help
I have a model with several materials in shop_materialpath. I want to get a list of each material (I will use this information to create groups later).
I made the following code, and it works !. My question is if I did it right?
Because with objects of many polygons, it is extremely slow.

import hou

root = hou.selectedNodes()[0]
geo = root.geometry()

path_a = []
path_b = []

for prim in geo.prims():
    shop = prim.attribValue('shop_materialpath')
    path_a.append(shop)
    if shop not in path_b:
        path_b.append(shop)
            

print path_b

 

Share this post


Link to post
Share on other sites

Yep, iterating over points/primitives in Python isn't the fastest operator. Bellow line

materials = list(set(geometry.primStringAttribValues("shop_materialpath")))

is considerably faster though, but if you're interested in creating groups per attribute value, I would consider VEX. Something like (untested):

int success = 0;
string material_name[] = split(primattrib(0, "shop_materialpath", @primnum, success), "/");
setprimgroup(0, material_name[-1], @primnum, 1);

 

  • Thanks 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×