Thursday, January 21, 2010

Custom Python operators

Here is the script that we did today:

# Get the data
this_node_obj = hou.node(".") #this is the same as hou.pwd()
geom_obj = this_node_obj.geometry()
points_list = geom_obj.points()

# Find the average
average = [0,0,0]
for point_obj in points_list:
    average[0] = average[0] + point_obj.position()[0] # could use +=
    average[1] = average[1] + point_obj.position()[1]
    average[2] = average[2] + point_obj.position()[2]
num = len(points_list)
average = [average[0] / num, average[1] / num, average[2] / num]

# Save the data
new_point_obj = geom_obj.createPoint()
new_point_obj.setPosition(average)

No comments:

Post a Comment