is there possible to grab elements attrib to array?

   910   4   1
User Avatar
Member
6 posts
Joined: 5月 2019
Offline
is there possible to grab elements attrib to array without any loop in VEX?
say if i’m running a vex snippet in detail mode. I want to get a sorted P.y attrs into an array
User Avatar
Member
900 posts
Joined: 2月 2016
Offline
Since houdini 19, Attribute Promote Sop has implemented a useful "array of all" method. Which is faster than using setdetailattrib() vex function. Since you want to store @P.y, you should first create a dummy attribute 'Py' as typing directly @P.y in Attrib Promote won't work.
This will just get the values into an array, sorted by point order.


To sort them by value, you could use the sort() function.
Check also the argsort(), which returns the list of indices sorted by the their values.

Note: these functions can be very cpu intensive.
User Avatar
Member
4506 posts
Joined: 2月 2012
Offline
goolyuyi
is there possible to grab elements attrib to array without any loop in VEX?
say if i’m running a vex snippet in detail mode. I want to get a sorted P.y attrs into an array

VEX can't, Python can:

node = hou.pwd()
geo = node.geometry()
py = sorted(geo.pointFloatAttribValues("P")[1::3])

https://www.sidefx.com/docs/houdini/hom/hou/Geometry.html [www.sidefx.com]
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 | animatrix2k7.gumroad.com
User Avatar
Member
6 posts
Joined: 5月 2019
Offline
Andr
Since houdini 19, Attribute Promote Sop has implemented a useful "array of all" method. Which is faster than using setdetailattrib() vex function. Since you want to store @P.y, you should first create a dummy attribute 'Py' as typing directly @P.y in Attrib Promote won't work.
This will just get the values into an array, sorted by point order.


To sort them by value, you could use the sort() function.
Check also the argsort(), which returns the list of indices sorted by the their values.

Note: these functions can be very cpu intensive.

it make sense, thanks!
User Avatar
Member
900 posts
Joined: 2月 2016
Offline
Andr
Note: these functions can be very cpu intensive.

Instead you could use Sort Sop in "by attribute" mode. Which it seems to lead to significant speed boost over vex-only methods (like 10x faster with 100k points).

I attach an example .hip file with the various options I came up.
Image Not Found
Edited by Andr - 2022年12月17日 10:11:38

Attachments:
promote_to_sorted_array.hiplc (109.8 KB)

  • Quick Links