Get Min/Max of Attribute with Pure Python

   1012   1   0
User Avatar
Member
95 posts
Joined: Feb. 2020
Offline
Using pure python (NOT using Min/Max and then reading those detail attributes) what's a good way to go about calculating the minimum and maximum of an attribute?

I would like calculate the min / max of a value inside of a parameter button callback script, like this one from the Attrib Remap Ql node.





I'd like the callback script to be relatively self contained and not need reference any detail attribute values in order to reduce node clutter.

Is the solution here just to iterate over all the total points in the geometry and then calculate values from that array? Or is there some more elegant solution / python function houdini provides for doing this? Nothing from the python docs is jumping out at me as a more elegant solution.
node = hom.node()

# Access the geometry
geometry = node.geometry()

# Specify the attribute name
attribute_name = 'your_attribute_name'  # Replace with your attribute name

# Get the attribute values based on the attribute type
if geometry.findPointAttrib(attribute_name).dataType() == hou.attribData.Float:
    values = geometry.pointFloatAttribValues(attribute_name)
elif geometry.findPointAttrib(attribute_name).dataType() == hou.attribData.Int:
    values = geometry.pointIntAttribValues(attribute_name)
elif geometry.findPointAttrib(attribute_name).dataType() == hou.attribData.String:
    values = geometry.pointStringAttribValues(attribute_name)
else:
    raise ValueError("Unsupported attribute type")

# Print the attribute values
for value in values:
    print(value)
Edited by wyhinton1 - July 5, 2024 23:34:11

Attachments:
minmaxquestionpython.png (31.2 KB)

User Avatar
Member
5100 posts
Joined: Feb. 2012
Offline
Hi,

Using pointFloatAttribValues and pointIntAttribValues functions is the fastest way:
https://www.sidefx.com/docs/houdini/hom/hou/Geometry.html#pointFloatAttribValues [www.sidefx.com]

node = hou.pwd()
geo = node.geometry()

values = geo.pointFloatAttribValues("y")

print(min(values), max(values))

Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com] https://lnk.bio/animatrix [lnk.bio]
  • Quick Links