hou.Prim
class
Each Prim resides inside a Geometry object and stores some sort of 3D geometric primitive, like a polygon, a NURBS curve, or a volume. Each primitive usually contains a set of Vertex objects, each of which references a Point object.
Subclasses: hou.Volume , hou.Surface , hou.Face , hou.Quadric , hou.Metaball
This class has a number of subclasses for the different primitive types, such as hou.Polygon and hou.Volume.
Methods
attribValue(self, name_or_attrib)→int,float,strortuple-
Return the value stored in this primitive for a particular attribute. The attribute may be specified by name or by hou.Attrib object.
Looking an attribute value using a hou.Attrib object is slightly faster than looking it up by name. When looking up attribute values inside a loop, look up the hou.Attrib object outside the loop, and pass it into this method.
When looking up the attribute values of all primitives, it is faster to call hou.Geometry.primFloatAttribValues than to call this method for each primitive in the geometry.
Raises hou.OperationFailed if no attribute exists with this name.
floatAttribValue(self, attrib)→float-
Return the primitive 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 float of size 1.
In most cases, you’ll just use hou.Prim.attribValue to access attribute values. Houdini uses this method internally to implement attribValue.
floatListAttribValue(self, name_or_attrib)→tupleoffloat-
Return the primitive 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 hou.Prim.attribValue.
intAttribValue(self, name_or_attrib)→int-
Return the primitive attribute value for a particular integer attribute of size 1. The attribute may be specified by name or by hou.Attrib object. See hou.Point.floatAttribValue for more information.
intListAttribValue(self, name_or_attrib)→tupleofint-
Return the primitive 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.Prim.floatListAttribValue for more information.
stringAttribValue(self, name_or_attrib)→str-
Return the primitive attribute value for a particular string attribute. The attribute may be specified by name or by hou.Attrib object. See hou.Prim.floatAttribValue for more information.
setAttribValue(self, name_or_attrib, attrib_value)-
Store an attribute value in this primitive. The attribute may be specified by name or by hou.Attrib object, and must be an existing primitive attribute in the geometry. 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.
# Create a float primitive attribute of size 3 named "Cd", and assign # each primitive a unique color. This code will work from inside a Python # SOP, but not from the Python shell. geo = hou.pwd().geometry() color_attrib = geo.addAttrib(hou.attribType.Prim, "Cd", (1.0, 1.0, 1.0)) num_prims = len(geo.prims()) color = hou.Color() for prim in geo.prims(): fraction = float(prim.number()) / num_prims # Give each primitive a different hue, but full saturation and value. # Store the RGB value in the attribute. color.setHSV((fraction * 255, 1, 1)) prim.setAttribValue(color_attrib, color.rgb())
attribType(self)→ hou.attribType enum value-
Return the enumerated value hou.attribType.Prim. Points, primitives, vertices, and geometry support the same set of methods for querying their attributes, and this method is one of them.
See also:
geometry(self)→ hou.Geometry-
Return the hou.Geometry object containing this primitive.
number(self)→int-
Return the number of this primitive. Primitives are numbered sequentially starting from 0, and the primitives returned by hou.Geometry.prims are in order by their number.
type(self)→ hou.primType enum value-
Return a hou.primType value containg the type of this primitive (e.g. polygon, NURBS curve, metaball, etc).
vertices(self)→ generator of hou.Vertex-
Return a sequence of the vertices contained in this primitive.
If the primitive is a face (e.g. a polygon or NURBS curve), the result corresponds to the order of the vertices in that face. If it is a surface (e.g. a NURBS mesh), however, the primitive has a 2D array of vertices, and this method returns all vertices in the 2D array, ordered by the rows.
See hou.Surface.vertex for more information about the relationship between the 2D vertex array and the sequential vertex index, and for more ways to access the vertices in a surface.
numVertices(self)→int-
A shortcut for
len(self.vertices()). You probably don’t need to call this method. vertex(self, index)→ hou.Vertex-
A shortcut for
self.vertices()[index]. You probably don’t need to call this method.This method supports negative indices to index from the end, just like
self.vertices()[index]would. Also, like Python’s indexing operator, it will raise IndexError when the index is out of range. isSplineType(self)→boolboundingBox(self)→ hou.BoundingBoxnearestToPosition(self, pos3)-
Given a sequence of three floats containing a position, find the location on this primitive that is closest to that position. Returns a tuple containing the u value on this primitive, the v value on this primitive, and the distance to this primitive.
closestPrim(self)→ hou.Prim orNoneminDistanceToPrim(self, prim)primsSharingPoints(self, num_points)→tupleof hou.PrimourUVAtClosestLocationToPrim(self, prim)