Getting sub material groups into a loop in python

   2381   3   0
User Avatar
Member
61 posts
Joined: 2月 2006
Offline
Hi,

I need to manipulate some group names brought in via alembic. I need to append a ‘_’ to the group name to match some previously defined material groups, I can't just change the material node names as this would break some pipeline dependencies elsewhere.

So I can do this for a single tab/folder material by putting :

for node in hou.selectedNodes():
for parm in node.parms():
if node.evalParm('group1'):
old = node.evalParm('group1')
new = ‘_’ + old
node.parm('group1').set(new)


But when there are sub-material tabs, the group1 material group is just evaluated in the first tab as

'____________________________________________name'

ie, it accumulates all the sub material group1 tabs for each ‘_’ and applies this to only the first group1 tab.
Obviously because I am not looping specifically for each sub material tab/folder in turn. I've turned towards evaluating the parmTemplateGroup but then I just get <parmTemplateGroup> returned for each 'group1 field, not the rename. What am I missing?

Cheers

Attachments:
i.png (47.4 KB)

User Avatar
Member
8041 posts
Joined: 9月 2011
Offline
I would loop over the range of values of ‘num_materials’.

def prefix_groups(material_node):
    num_materials = material_node.evalParm('num_materials')
    for i in range(1,num_materials+1):
        grp = material_node.parm('group{:d}'.format(i))
        grp.set('_'+grp.eval())
User Avatar
Member
8041 posts
Joined: 9月 2011
Offline
Alternatively, you can use filter:

def prefix_groups(material_node):
    num_materials = material_node.parm('num_materials')
    materials = num_materials.multiParmInstances()
    for parm in filter(lambda p: p.name().startswith('group'), materials):
        parm.set('_'+parm.eval())
User Avatar
Member
61 posts
Joined: 2月 2006
Offline
Thanks!
  • Quick Links