Jump to content
Sign in to follow this  
Duder

NumPy to point arrayAttributes

Recommended Posts

It looks like it's possible to set point attributes all at once instead of looping through them one at a time.

I was trying to do it with NumPy, but can't quite get it right. Seems to be problem with the custom attribute being an array.

Given an array with the same shape,i.e., number of points x array size it looks like it should work, but doesn't.

Incidentally, the NumPy array will contain data from a file. I can't tell there's a better way to pull file data straight into something like VEX, hence the NumPy array.

Here's my test code:

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


pt0 = [1.0, 0.0, 0.0]
point = g.createPoint()
point.setPosition(pt0)

pt_1 = [0.5, 0.5, -1.0]
point_2 = g.createPoint()
point_2.setPosition(pt_1)

pt_2 = [1.5, -2.5, 0.0]
point_3 = g.createPoint()
point_3.setPosition(pt_2)


g.addArrayAttrib(hou.attribType.Point, "MyFloats", hou.attribData.Float, 8)
gp = g.points()


# This works fine
'''
gb0 = (0.5, 0.3, 0.1, 0.1, 0.6, 0.2, 0.3, 0.8)
gp[0].setAttribValue("MyFloats", gb0)

gb1 = (0.2, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1)
gp[1].setAttribValue("MyFloats", gb1)

gb2 = (0.7, 0.6, 0.1, 0.5, 0.1, 0.2, 0.8, 0.9)
gp[2].setAttribValue("MyFloats", gb2)
'''


import numpy as np
y = np.arange(24, dtype=np.float32).reshape(3,8)
g.setPointFloatAttribValues("MyFloats", y)   # error
print g.pointFloatAttribValues("MyFloats")   # error

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×