Houdini Python for loop cycle through prim attribute

   410   2   0
User Avatar
Member
84 posts
Joined: 10月 2013
Offline
Hi,

I'm working on automating some steps in my alembic import process. I have a python node with code that cycles through all primitives in the alembic file, and creates a string attribute called “name” with a value based on the path variable.

After this for loop, I would like to cycle through the name attribute in a for loop and run code for each object that way. I tried

<code>
objLs = geo.findPrimAttrib(“name”)
</code>

but that does not seem to be correct. I want to get a list of values for that attribute, that I can cycle through. So, I would have a list with object names.

Thank you.

Adnan
User Avatar
Member
4964 posts
Joined: 7月 2007
Offline
you can do that with 2 oneliner prim wrangles:
assuming your path is in more or less standard hierarchy “/some/parent/objects/objectname/geoname”
to extract objetname token (second from the end) as s@name attribtute you can do
s@name = split(s@path, "/")[-2];
but obviously you can combine tokens to get more unique name or process otherwise as you need
and then another prim wrangle to get array of all unique name values
s[]@names = uniquevals(0, "prim", "name");

but to answer your original Python question, you can also do it without any loop:
attrib = geo.findPrimAttrib("name")
unique_names = attrib.strings()
Edited by tamte - 2020年6月24日 02:31:59
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
84 posts
Joined: 10月 2013
Offline
As always, thank you Tomas. The python code worked beautifully and you gave me some more information to help in my learning. Thanks so much!

Adnan
  • Quick Links