Jump to content

get list of materials


nilsoncardososa

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

 

Link to comment
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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...