hou.Geometry
class
A Geometry object contains the points and primitives that define a 3D geometric shape. For example, each SOP node in Houdini generates a single Geometry object.
If you ask a SOP for its geometry via hou.SopNode.geometry, you’ll get a read-only reference to it. If the SOP recooks, the corresponding Geometry object will update to the SOP’s new geometry. If the SOP is deleted, accessing the Geometry object will raise a hou.ObjectWasDeleted exception. If you call methods that try to modify the geometry, they will raise a hou.GeometryPermissionError exception.
If you do not want the geometry to update when the SOP recooks, you can call hou.Geometry.freeze. freeze returns another Geometry object that will not change when the SOP recooks. Accessing frozen Geometry is slightly faster, since Houdini does not need to look up the SOP node for each access, so you may want to use frozen geometry for speed-crucial operations.
If you're writing a SOP using Python, you will have read-write access to the geometry, and it will be frozen. To create a Python-defined SOP, select File > New Operator Type... and place the Python code in the Code tab.
Methods
findPointAttrib(self, name)→ hou.Attrib orNone-
Look up a point attribute by name. Returns the corresponding hou.Attrib object, or None if no attribute exists with that name.
Note that the point position attribute is named
Pand is 3 floats in size. Also, the point weight attribute is namedPwand is 1 float in size. These attributes always exist in HOM, even though they are not listed by Houdini’s UI.See hou.Point.attribValue for an example.
findPrimAttrib(self, name)→ hou.Attrib orNone-
Look up a primitive attribute by name. Returns the corresponding hou.Attrib object, or None if no attribute exists with that name.
findVertexAttrib(self, name)→ hou.Attrib orNone-
Look up a vertex attribute by name. Returns the corresponding hou.Attrib object, or None if no attribute exists with that name.
findGlobalAttrib(self, name)→ hou.Attrib orNone-
Look up a global (a.k.a. detail) attribute by name. Returns the corresponding hou.Attrib object, or None if no attribute exists with that name.
pointAttribs(self)→tupleof hou.Attrib-
Return a tuple of all the point attributes.
Note that the point position attribute is named
Pand is 3 floats in size. Also, the point weight attribute is namedPwand is 1 float in size. These attributes always exist in HOM, even though they are not listed by Houdini’s UI. primAttribs(self)→tupleof hou.Attrib-
Return a tuple of all the primitive attributes.
vertexAttribs(self)→tupleof hou.Attrib-
Return a tuple of all the vertex attributes.
globalAttribs(self)→tupleof hou.Attrib-
Return a tuple of all the global (a.k.a. detail) attributes.
addAttrib(self, type, name, default_value, transform_as_normal=False)→ hou.Attrib-
Create a new point, primitive, vertex, or global (a.k.a. detail) attribute. Returns a hou.Attrib object describing the newly created attribute. You would typically call this method from the code of a Python-defined SOP.
type
A hou.attribType value to specify if the new attribute should be a point, primitive, vertex, or global attribute.
name
The new attribute’s name. Each attribute in the geometry must have a unique name.
default_value
The default value for this attribute. When an attribute is created, all existing elements (e.g. primitives or points) will store this value. As well, elements that you add later will also use this value.
This value also determines the attribute’s data type, and may be one of the following:
-
an integer
-
a float
-
a string
-
an integer sequence
-
a float sequence
If the default value is a sequence of integers or floats, the sequence size will determine the attribute’s size. Otherwise, the attribute’s size is 1.
transform_as_normal
This parameter is only available when the default value is a sequence of 3 floats. For such attributes, Houdini will not modify the attribute values when it transforms (translates, rotates, etc.) the geometry. If you want to the attribute to be transformed as a vector (such as a normal vector) when Houdini transforms the geometry, set this parameter to
True.Raises hou.GeometryPermissionError if this geometry is not modifiable.
Raises hou.OperationFailed if an attribute with this name already exists. If you are familiar with the C++ Houdini Development Kit (HDK), you know that Houdini can support attributes with the same name but with different types. However, many SOPs do not let you distinguish between attributes that have the same name, and multiple attributes with the same name are discouraged. For this reason, you cannot create them with this method.
Raises hou.OperationFailed if transform_as_normal is
Trueand the default value is not a sequence of 3 floats.# Create an integer point attribute of size 1 named "population", and # create 5 points with attribute values 0, 5, 10, 15, and 20. This code # will work from inside a Python SOP, but not from the Python shell. geo = hou.pwd().geometry() population_attrib = geo.addAttrib(hou.attribType.Point, "population", 0) for i in range(5): point = geo.createPoint() point.setPosition((i, 0, 0)) point.setAttribValue(population_attrib, i * 5)
See also:
-
attribValue(self, name_or_attrib)→int,float,str, ortuple-
Return the global (a.k.a. detail) attribute value for a particular attribute. The attribute may be specified by name or by hou.Attrib object.
Raises hou.OperationFailed if no attribute exists with this name.
floatAttribValue(self, name_or_attrib)→float-
Return the global (a.k.a. detail) attribute value for a particular floating point attribute. The attribute may be specified by name or by hou.Attrib object.
Raises hou.OperationFailed if no attribute exists with this name or the attribute is not a float of size 1.
In most cases, you’ll just use hou.Geometry.attribValue to access attribute values. Houdini uses this method internally to implement attribValue.
floatListAttribValue(self, name_or_attrib)→tupleoffloat-
Return the global (a.k.a. detail) attribute value for a particular floating point attribute. The attribute may be specified by name or by hou.Attrib object. The return value is a list of floats.
It is valid to call this method when the attribute’s size is 1. In this case, a list with one element is returned.
See also:
intAttribValue(self, name_or_attrib)→int-
Return the global (a.k.a. detail) attribute value for a particular integer attribute of size 1. The attribute may be specified by name or by hou.Attrib object. See hou.Geometry.floatAttribValue for more information.
intListAttribValue(self, name_or_attrib)→tupleofint-
Return the global (a.k.a. detail) attribute value for a particular integer attribute. The attribute may be specified by name or by hou.Attrib object. The return value is a list of ints. See hou.Geometry.floatListAttribValue for more information.
stringAttribValue(self, name_or_attrib)→str-
Return the global (a.k.a. detail) attribute value for a particular string attribute. The attribute may be specified by name or by hou.Attrib object. See hou.Geometry.floatAttribValue for more information.
setGlobalAttribValue(self, name_or_attrib, attrib_value)-
Set a global (a.k.a. detail) attribute value. The attribute may be specified by name or by hou.Attrib object. You would typically call this method from the code of a Python-defined SOP.
Raises hou.OperationFailed if no attribute exists with this name or if the attribute’s data type does not match the value passed in. If the attribute’s size is more than 1, the attribute value must be a sequence of integers/floats, and the size of the sequence must match the attribute’s size.
Raises hou.GeometryPermissionError if this geometry is not modifiable.
# This code will work from inside a Python SOP, but not from the Python # shell. geo = hou.pwd().geometry() geo.addAttrib(hou.attribType.Global, "author", "") geo.addAttrib(hou.attribType.Global, "version", (0, 0, 0)) geo.setGlobalAttribValue("author", "Joe") geo.setGlobalAttribValue("version", (1, 0, 7))
See also:
attribType(self)→ hou.attribType enum value-
Return the enumerated value hou.attribType.Global. Points, primitives, vertices, and geometry support the same set of methods for querying their attributes, and this method is one of them.
See also:
averagePointAttribValue(self, attrib_name, index)averagePointAttribValueByType(self, attrib_type, index)averagePrimAttribValue(self, attrib_name, index)averagePrimAttribValueByType(self, attrib_type, index)averageVertexAttribValue(self, attrib_name, index)averageVertexAttribValueByType(self, attrib_type, index)boundingBox(self)→ hou.BoundingBox-
Return an axis-aligned 3D bounding box that is sized and positioned to be large enough to hold this geometry.
centroid(self)→ hou.Vector3createPoint(self)→ hou.Point-
Create a new point located and (0, 0, 0) and return the corresponding hou.Point object. You would typically call this method from the code of a Python-defined SOP.
If the geometry contains point attributes, the new point receives the default values for those attributes.
Raises hou.GeometryPermissionError if this geometry is not modifiable.
See hou.Geometry.addAttrib, hou.Geometry.createPolygon, and hou.Face.addVertex for examples.
createPolygon(self)→ hou.Polygon-
Create a new polygon and return the corresponding hou.Polygon object. You would typically call this method from the code of a Python-defined SOP.
The newly created polygon has no vertices. Use hou.Face.addVertex to add them. The polygon is also closed (see hou.Face.isClosed for more information).
If the geometry contains primitive attributes, the new polygon receives the default values for those attributes.
Raises hou.GeometryPermissionError if this geometry is not modifiable.
geo = hou.pwd().geometry() poly = geo.createPolygon() for position in (0,0,0), (1,0,0), (0,1,0): point = geo.createPoint() point.setPosition(position) poly.addVertex(point)
See hou.Face.addVertex for a slightly more complicated example.
createNURBSCurve(self, num_vertices=4, is_closed=False)→ hou.Face-
Create a new NURBS with the specified number of vertices and return it. You would typically call this method from the code of a Python-defined SOP.
num_vertices
The number of verticies in the curve. A new point is added to the geometry for each vertex, and this point is located at the origin until you change its position. You can also add more vertices with hou.Face.addVertex.
The order of the NURBS curve is 4, so the curve must always have a minimum of 4 vertices. If you specify too few vertices, this method raises hou.OperationFailed.
is_closed
Controls if the curve is open or closed; see hou.Face.isClosed for more information. If not specified, the resulting curve is open. This behaviour is different from hou.Geometry.createPolygon, where the new polygon is closed. You can also open or close it with hou.Face.setIsClosed.
If the geometry contains primitive attributes, the new curve receives the default values for those attributes.
# This code will work from inside a Python SOP, but not from the Python # shell. geo = hou.pwd().geometry() curve = geo.createNURBSCurve(10) for vertex in curve.vertices(): vertex.point().setPosition((i, i % 3, 0))
Raises hou.GeometryPermissionError if this geometry is not modifiable.
See also:
createBezierCurve(self, num_vertices=4, is_closed=False)→ hou.Face-
Create a new Bezier curve with the specified number of vertices and return it. You would typically call this method from the code of a Python-defined SOP.
The Bezier curve has order 4, and the
is_closedparameter determines if it is open or closed (see hou.Face.isClosed for more information). An open Bezier curve must have3n+1vertices for some integern>=1(so valid values are 4, 7, 10, etc.). A closed Bezier curve must have3nvertices (e.g. 3, 6, 9, etc.). You cannot use hou.Face.setIsClosed on a Bezier curve, since the number of vertices would need to change.See hou.Geometry.createNURBSCurve for more information.
createNURBSSurface(self, rows, cols, is_closed_in_u=False, is_closed_in_v=False)→ hou.Surface-
Create a NURBS surface in the XY plane centered at the origin with size (1, 1) and return it. You would typically call this method from the code of a Python-defined SOP.
rows, cols
Determines the size of the 2D array of vertices defining the control points of the surface. The order of the NURBS surface is 4 in each of the u and v dimensions, so rows and cols much each be at least 4.
is_closed_in_u, is_closed_in_v
Controls if the surface is open or closed in each of the dimensions; see hou.Surface.isClosedInU for more information. If not specified, the default behaviour is to build an open surface.
If the geometry contains primitive attributes, the new surface receives the default values for those attributes.
You can move or resize the surface using hou.Prim.transform.
Raises hou.GeometryPermissionError if this geometry is not modifiable.
Raises hou.OperationFailed if the number of rows and/or columns is invalid.
# This code will work from inside a Python SOP, but not from the Python # shell. geo = hou.pwd().geometry() # Create a surface with a 10x10 grid of vertices. surf = geo.createNURBSSurface(10, 10) # Initially, the center is at (0, 0, 0), size is (1, 1, 1), on the XY # plane. Scale to (20, 10) and rotate into the XZ plane. geo.transformPrims((surf,), hou.hmath.buildScale((20, 10, 1)) * hou.hmath.buildRotateAboutAxis((1, 0, 0), 90))
See also:
createBezierSurface(self, rows, cols, is_closed_in_u=False, is_closed_in_v=False)→ hou.Surface-
Create a Bezier surface in the XY plane centered at the origin with size (1, 1) and return it. You would typically call this method from the code of a Python-defined SOP.
rows, cols
Determines the size of the 2D array of vertices defining the control points of the surface. The surface must have
3n+1,n>=1(e.g. 4, 7, 10, …) rows/columns if it is open in that dimension, and3n,n>=1(e.g. 3, 6, 9, …) rows/columns if it is closed in that dimension. Otherwise, this method raises hou.OperationFailed.Note that the number of rows corresponds to
vand the number or columns corresponds tou, which can be slightly confusing. For example,geo.createBezierSurface(9, 7, is_closed_in_u=False, is_closed_in_v=True)is valid, butgeo.createBezierSurface(9, 7, is_closed_in_u=True, is_closed_in_v=False)raises hou.OperationFailed.is_closed_in_u, is_closed_in_v
Determines if it is open or closed in each of the
uandvdimensions; see hou.Surface.isClosedInU for more information.You can move or resize the surface using hou.Prim.transform.
If the geometry contains primitive attributes, the new surface receives the default values for those attributes.
Raises hou.GeometryPermissionError if this geometry is not modifiable.
import math # This code will work from inside a Python SOP, but not from the Python # shell. geo = hou.pwd().geometry() # Build a tube-like object about the y axis. num_rows, num_cols = (10, 9) surf = geo.createBezierSurface(num_rows, num_cols, is_closed_in_u=True) for v_index in range(num_rows): for u_index in range(num_cols): angle = u_index * (2.0 * math.pi) / num_cols surf.vertex(u_index, v_index).point().setPosition( (math.cos(angle), v_index / float(num_cols-1), math.sin(angle)))
createMeshSurface(self, rows, cols, is_closed_in_u=False, is_closed_in_v=False)→ hou.Surface-
Create a quadrilateral mesh surface in the XY plane centered at the origin with size (1, 1) and return it. You would typically call this method from the code of a Python-defined SOP.
Note that a mesh object is not the same as a set of polygons defining the same shape. A mesh object is a single primitive.
See hou.Geometry.createNURBSSurface for more information.
createVolume(self, xres, yres, zres, bounding_box=None)→ hou.Volume-
Given the x, y, and z resolution (or size) of a voxel array, add a new volume primitive to the geometry and return it. The values in the new volume’s voxels are all zero.
xres, yres, zres
Integers greater than zero that specify the size of the voxel array in one dimension. Raises hou.OperationFailed if any of these values are not positive.
bounding_box
A hou.BoundingBox that specifies the volume’s 3D size. Note that this size is independent of the volume’s voxel resolution. If this parameter is None, Houdini uses a bounding box going from (-1,-1,-1) to (1,1,1).
createMetaball(self)→ hou.MetaballdeletePrims(self, prims, keep_points=False)-
Delete a sequence of primitives. You would typically call this method from the code of a Python-defined SOP.
keep_points
if
True, the primitive will be deleted but its points will remain.To delete a single primitive, pass in a sequence with one primitive.
Raises hou.GeometryPermissionError if this geometry is not modifiable.
# Delete every other primitive: prims = [p for p in geo.prims() if p.number() % 2 == 0] geo.deletePrims(prims) # Delete the first primitive: geo.deletePrims([geo.iterPrims()[0]])
deletePoints(self, points)-
Delete a sequence of points. You would typically call this method from the code of a Python-defined SOP.
Note that Houdini will delete any vertices that reference the point. For example, suppose you have a box with 6 polygons, each with 4 vertices. Also suppose that each point on the box is shared by 3 vertices on 3 separate polygons. If you delete one of those points, Houdini will remove each of those vertices from their corresponding polygons, leaving 3 polygons with 4 vertices and 3 polygons with 3 vertices.
To delete a single primitive, pass in a sequence with one point.
Raises hou.GeometryPermissionError if this geometry is not modifiable.
findPointGroup(self, group_name)→ hou.PointGroup orNonefindPointGroups(self, pattern)→tupleof hou.PointGrouppointGroups(self)→tupleof hou.PointGroupfindPrimGroup(self, group_name)→ hou.PrimGroup orNonefindPrimGroups(self, pattern)→tupleof hou.PrimGroupprimGroups(self)→tupleof PrimGroupsfreeze(self)→ hou.Geometry-
Return another Geometry object that is not linked to a particular SOP.
When you call hou.SopNode.geometry, the resultant Geometry object retains a reference to that SOP, and is said to be unfrozen. Each time you access points, primitives, attributes, etc. in an unfrozen Geometry object, Houdini uses the SOP’s latest cooked geometry. So, if you change parameters or change the time for an animated SOP, the Geometry object will update to the SOP’s new geometry.
A frozen Geometry object, however, is not associated with a particular SOP. When the SOP recooks, the frozen Geometry object will save its own copy of the point and primitive data, and is unaffected by subsequent changes to the SOP. When a frozen Geometry object is destroyed, any geometry copy it created is destroyed.
Calling this method on an unfrozen Geometry object returns a frozen one. Calling it on a frozen object has no effect, and it returns a frozen object.
Note that accessing a Geometry object’s points, primitives, attributes, etc. may be faster when dealing with frozen objects. So, you may want to work with frozen Geometry in speed-sensitive operations.
sopNode(self)→ hou.SopNode-
If the Geometry is not frozen, return the hou.SopNode object corresponding to this Geometry. Otherwise, return None.
See hou.Geometry.freeze for more information on frozen geometry.
points(self)→tupleof hou.Point-
Return a tuple of all the points in the geometry.
See also the hou.Geometry.iterPoints method.
iterPoints(self)→ generator of hou.Point-
Return a generator that iterates through all the points in the geometry.
Whereas hou.Geometry.points allocates and returns a tuple of all the points in the geometry, this method returns a generator object that will allocate hou.Point objects on demand. This object is very fast at random access into the sequence.
If you're accessing a specific point by index and the geometry contains many points, it is faster to use iterPoints() than points(). If, however, you are iterating over all the points in the geometry, it is generally faster to use points() than iterPoints().
# This is preferred: geo.iterPoints()[23] # over this: geo.points()[23] # But this is preferred: for point in geo.points(): ...process point... # over this: for point in geo.iterPoints(): ...process point...
globPoints(self, patern)→tupleof hou.Point-
Return a tuple of points corresponding to a pattern of point numbers.
The pattern format is the same one used by the group fields on SOP nodes that take point selections. Elements in the pattern are separated by spaces, and elements can be point numbers, point number ranges, or group names.
This method can be useful when writing a Python SOP that works on only a selected set of points.
Raises hou.OperationFailed if the pattern is not valid or if it refers to a group that does not exist. Note that an empty pattern is considered to be invalid. Numbers that do not refer to valid points are not errors, and simply do not match points.
# Return a tuple containing points 5 and 7. geo.globPoints("5 7") # Return a tuple containing points 5 to 10. geo.globPoints("5-10") # Return a tuple containing all the points in the pointgroup called group1. geo.globPoints("group1") # Return all the points except those from 0 to 98. geo.globPoints("!0-98") # Return points 5, 10 to 20, and those in group1. geo.globPoints("5 group1 10-20")
The following Python SOP example is behaves similarly to the Point sop.
# This code will work from inside a Python SOP, but not from the Python # shell. It assumes the Python sop has the following parm tuples: # group: A string containing which points to affect # t: A set of 3 floats that behaves like the point sop's position # parameter. Set these parameters to the expressions ($TX, $TY, $TZ). geo = hou.pwd().geometry() # Use the group field to determine which points to affect. If it's blank, # operate on all points. pattern = hou.ch("group") if pattern == "": points = geo.points() else: points = geo.globPoints(pattern) # Loop through the points, setting the SOP's current point as we go. # Then evaluate the t parm tuple, so it can use the current point (e.g. # with hscript's $TX or Python's pwd().curPoint()). for point in points: hou.pwd().setCurPoint(point) new_position = hou.pwd().evalParmTuple("t") point.setPosition(new_position)
findClosestPoint(self, pos3)→ hou.Point orNonefindClosestPrim(self, pos3)→ hou.Prim orNonenearestPrim(self, position)→ (hou.Prim orNone,float,float,float)-
Given a sequence of three floats containing a position, find the location on the primitive closest to that position and return a tuple containing that primitive, the u value on the primitive, the v value on the primitive, and the distance to the primitive.
Note that the first value in the return tuple can be None if there are no primitives in the geometry.
findParticleById(self, particle_id)→ hou.Point orNonepointFloatAttribValues(self, name)→tupleoffloat-
Return a tuple of floats containing one attribute’s values for all the points.
This method only works on int or float attributes. If the attribute contains more than one element, each point will correspond to multiple values in the result. For example, if “Cd” is a float attribute of size 3 and there are 3 points with values (0.1, 0.2, 0.3), (0.5, 0.5, 0.5), and (0.8, 0.7, 0.6) then the result will be (0.1, 0.2, 0.3, 0.5, 0.5, 0.5, 0.8, 0.7, 0.6).
Calling this method is faster than looping over all the points and calling hou.Point.attribValue
If the attribute name is invalid or the attribute is not an int or float (e.g. it’s a string attribute), this method raises hou.OperationFailed.
Note that you cannot pass a hou.Attrib object to this method like you can with many methods dealing with attributes. However, you can use hou.Attrib.name to easily get the name from an Attrib object.
pointFloatAttribValuesAsString(self, name)→str-
Return a string representation of the floats of one attribute’s value for all the points. This method is faster than hou.Geometry.pointFloatAttribValues, and you can use the
arraymodule to convert the string into a Python sequence.This method provides a faster implementation of the following:
import array def pointFloatAttribValuesAsString(self, name): return array.array("f", self.pointFloatAttribValues(name)).tostring()
You can convert the return value from this method to an array using the following method:
import array def pointFloatAttribValuesAsArray(geometry, name): a = array.array("f") a.fromstring(geometry.pointFloatAttribValuesAsString(name)) return a
See hou.Geometry.pointFloatAttribValues for more information.
setPointFloatAttribValues(self, name, values)-
For a particular attribute, set the attribute values for all points. You would typically call this method from the code of a Python-defined SOP.
name
The name of the point attribute.
values
A sequence of int or float values in the same format as that returned by hou.Geometry.pointFloatAttribValues. See that method for more information.
Raises hou.OperationFailed if the attribute name is not valid, the attribute is not an int or float (i.e. it’s a string), or the array of values it not the correct size.
Raises hou.GeometryPermissionError if this geometry is not modifiable.
Also see hou.Geometry.pointFloatAttribValues.
setPointFloatAttribValuesFromString(self, name, values)-
For a particular attribute, set the attribute values for all points from a string representation of a sequence of single precision float values. This method is faster than hou.Geometry.setPointFloatAttribValues.
Raises hou.OperationFailed if the length of the string is not `len(self.iterPoints() * 4).
See hou.Geometry.setPointFloatAttribValues and hou.Geometry.pointFloatAttribValuesAsString for more information.
The following example function accepts an
array.array("f")and sets the attribute values to its contents:def setPointFloatAttribValuesFromArray(geometry, arr): assert(arr.typecode == "f") geometry.setPointFloatAttribValuesFromString(arr.tostring())
prims(self)→tupleof hou.Prim-
Return a tuple of all the primitives in the geometry. The primitives returned will be subclasses of hou.Prim (e.g.polygons, volumes, etc.).
See also:
iterPrims(self)→ generator of hou.Prim-
Return a generator that iterates through all the primitives in the geometry.
Whereas hou.Geometry.prims allocates and returns a tuple of all the primitives in the geometry, this method returns a generator object that will yield hou.Prim objects on demand. This object is very fast at random access into the sequence.
If you're accessing a specific primitive by index and the geometry contains many primitives, it is faster to use iterPrims() than prims(). If, however, you are iterating over all the primitives in the geometry, it is generally faster to use prims() than iterPrims().
# This is preferred: geo.iterPrims()[23] # over this: geo.prims()[23] # But this is preferred: for prim in geo.prims(): ...process prim... # over this: for prim in geo.iterPrims(): ...process prim...
See also the hou.Geometry.prims method.
globPrims(self, patern)→tupleof hou.Prim-
Return a tuple of primitives corresponding to a pattern of primitive numbers.
The pattern format is the same one used by the group fields on SOP nodes that take primitive selections. See hou.Geometry.globPoints for more information.
primFloatAttribValues(self, name)→tupleoffloat-
Return a tuple of floats containing one attribute’s values for all the primitives.
This method only works on int or float attributes. If the attribute contains more than one element, each primitive will correspond to multiple values in the result. For example, if “Cd” is a float attribute of size 3 and there are 3 primitives with values (0.1, 0.2, 0.3), (0.5, 0.5, 0.5), and (0.8, 0.7, 0.6) then the result will be (0.1, 0.2, 0.3, 0.5, 0.5, 0.5, 0.8, 0.7, 0.6).
Calling this method is faster than looping over all the primitives and calling hou.Prim.attribValue
If the attribute name is invalid or the attribute is not an int or float (e.g. it’s a string attribute), this method raises hou.OperationFailed.
Note that you cannot pass a hou.Attrib object to this method like you can with many methods dealing with attributes. However, you can use hou.Attrib.name to easily get the name from an Attrib object.
primFloatAttribValuesAsString(self, name)→str-
Return a string representation of the floats of one attribute’s value for all the primitives. This method is faster than hou.Geometry.primFloatAttribValues, and you can use the
arraymodule to convert the string into a Python sequence.This method provides a faster implementation of the following:
import array def primFloatAttribValuesAsString(self, name): return array.array("f", self.primFloatAttribValues(name)).tostring()
You can convert the return value from this method to an array using the following method:
import array def primFloatAttribValuesAsArray(geometry, name): a = array.array("f") a.fromstring(geometry.primFloatAttribValuesAsString(name)) return a
See hou.Geometry.primFloatAttribValues for more information.
setPrimFloatAttribValues(self, name, values)-
For a particular attribute, set the attribute values for all primitives. You would typically call this method from the code of a Python-defined SOP.
name
The name of the primitive attribute.
values
A sequence of int or float values in the same format as that returned by hou.Geometry.primFloatAttribValues. See that method for more information.
Raises hou.OperationFailed if the attribute name is not valid, the attribute is not an int or float (i.e. it’s a string), or the array of values it not the correct size.
Raises hou.GeometryPermissionError if this geometry is not modifiable.
Also see hou.Geometry.primFloatAttribValues.
setPrimFloatAttribValuesFromString(self, name, values)-
For a particular attribute, set the attribute values for all primitives from a string representation of a sequence of single precision float values. This method is faster than hou.Geometry.setPrimFloatAttribValues.
Raises hou.OperationFailed if the length of the string is not `len(self.iterPrims() * 4).
See hou.Geometry.setPrimFloatAttribValues and hou.Geometry.primFloatAttribValuesAsString for more information.
The following example function accepts an
array.array("f")and sets the attribute values to its contents:def setPrimFloatAttribValuesFromArray(geometry, arr): assert(arr.typecode == "f") geometry.setPrimFloatAttribValuesFromString(arr.tostring())
saveToFile(self, file_name)-
Save the contents of the geometry object to a file. The file extension determines what file format to use.
All file formats supported by Houdini (e.g. geo, bgeo, obj, etc.), including extensions listed in
GEOio, are supported. If the file extension is not recognized, the bgeo format is used.Raises hou.OperationFailed if the path to the file is invalid or there were permission or other I/O errors.
transform(self, matrix)-
Transforms (e.g. rotates, scales, translates, etc.) the geometry by a transformation matrix. You would typically call this method from the code of a Python-defined SOP.
See hou.hmath for functions that build transformation matrices.
Raises hou.GeometryPermissionError if this geometry is not modifiable.
transformPrims(self, prims, matrix)-
Transforms a set of primitives (e.g. rotates, scales, translates, etc.) by a transformation matrix. You would typically call this method from the code of a Python-defined SOP.
import math # This code will work from inside a Python SOP, but not from the Python # shell. def createCircle(geo, num_vertices=10): # Create a closed curve with the specified number of vertices. curve = geo.createNURBSCurve(num_vertices) curve.setIsClosed(True) # Arrange the points into a unit circle on the XZ plane, # centered about the origin. for i, vertex in enumerate(curve.vertices()): angle = i * (2.0 * math.pi) / num_vertices position = (math.cos(angle), 0, math.sin(angle)) vertex.point().setPosition(position) return curve # Create a bunch of circles on the XZ plane, tilt them slightly # about X, translate them away from the origin, and rotate each # one about the y axis by a different amount. geo = hou.pwd().geometry() num_copies = 20 for i in range(num_copies): curve = createCircle(geo) geo.transformPrims([curve], hou.hmath.buildRotateAboutAxis((1, 0, 0), 30) * hou.hmath.buildTranslate((2, 0, 0)) * hou.hmath.buildRotateAboutAxis((0, 1, 0), i * 360.0 / num_copies))
See hou.hmath functions that build transformation matrices.
Raises hou.GeometryPermissionError if this geometry is not modifiable.
metaballWeight(self, pos3)seamPoints(self, seam_half)→tupleof hou.Point