Finding primitives by name

   2435   5   1
User Avatar
Member
6 posts
Joined: Feb. 2019
Offline
Hello everyone,

I've looked through the documentation thoroughly, and I can't find a simple way to find all primitives with a specific name.

Using Python it can be done with a short list comprehension:
(bracket) prim for prim in geo.prims() if prim.attribValue(“name”) == “michael” (closed bracket)

But this loops over every single primitive.
Q: Is there a faster way to do this rather than looping over all prims?
(My hope is that Houdini indexes things by name for super fast lookup.)

Thanks!
~Michael
Edited by socratica - July 14, 2019 19:16:17
User Avatar
Member
7802 posts
Joined: Sept. 2011
Offline
I'm not sure what you mean by finding primitives. Does a group work? @name='foo'should work in group fields or for creating a group using a group combine sop.
User Avatar
Member
6 posts
Joined: Feb. 2019
Offline
I was going to use a group, but I read on the Node name docs [www.sidefx.com] that names are more efficient than groups. So I was hoping to get used to using names for a lot of my computations in Python nodes.

My gut tells me I'm prematurely optimizing… But I'm still curious if there's a method that will return all primitives with a given name.
User Avatar
Member
900 posts
Joined: Feb. 2016
Offline
you can iterate by the name attribute with a for loop.

Or you could use a findattribval() function in a vex wrangle
User Avatar
Member
6 posts
Joined: Feb. 2019
Offline
Thanks! I need to leave my Python comfort zone and really learn vex since speed is a focus of mine.
User Avatar
Member
4528 posts
Joined: Feb. 2012
Offline
You can use the nametoprim VEX function which uses findattribval function which is way faster than looping over primitives manually.
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | pragmaticvfx.gumroad.com
  • Quick Links