Component selections are not tied to any specific hou.Geometry. Therefore most method on this class must be passed a Geometry object to look up information about individual components. This explicit separation allows the selection class to be used as a utility class for processing geometry topology (growing the set of components, shrinking it, finding the boundary, etc.). This separation also avoids any expectations that changing the contents of a selection object might be expected to update the selection visible on some geometry in the viewport. Setting the visible viewport selection must always be an explicit operation on a hou.SopNode in order for Houdini to be able to track changes properly.
If a selection object is returned from a call to hou.Geometry.selection,
hou.GeometrySelection.selections, or a hou.SopNode.selection, the
selection cannot be modified. A copy of the selection must be made first with
the freeze()
method. This new selection can be modified, and passed back into
a hou.SopNode.setSelection if desired. Because each SOP has a selection
for each component type, when you set a new selection it will replace the
existing selection of that component type. Note that this may not result in
the visible selection in the viewport changing if the viewport is not
currently configured to select that component type. The viewport selection
type can be controlled with the hou.SceneViewer class. A selection
created by calling any of the hou.Selection()
initializer methods are
created in a modifiable state, so a call to freeze()
is not required.
A selection returned from a hou.Geometry or a hou.SopNode is a
reference to the source selection, and so will change if the selection on the
source geometry is changed. This seems like a departure from the separation of
selection objects from any particular geometry, however it matches the
behavior of the hou.Geometry class returned from a SOP node. This is
because the underlying selection data is shared with the SOP rather than
copied. The freeze()
method can be used to force a copy of the selection
data that is disconnected from any particular SOP (as well as allowing the
selection contents to be modified).
Methods ¶
__init__(selection_type)
Creates a new empty Selection object with one of the hou.geometryType
values passed as the selection_type
to control the type of component
that can be part of this selection.
__init__(geo, selection_type, selection_string)
Creates a new Selection object with initial contents defined by a group string evaluated on a particular Geometry object.
geo
A hou.Geometry object that is used when evaluating the selection string.
selection_type
A hou.geometryType value to indicate the type of component that will appear in this Selection.
selection_string
Any string that might appear in a SOP Group parameter that describes which components to include in the selection. This string may include any features supported by SOP group parsing, such as group names, numeric ranges, and attribute value tests.
__init__(prims)
Creates a new primitive component selection from the passed in sequence of hou.Prim objects.
__init__(points)
Creates a new point component selection from the passed in sequence of hou.Point objects.
__init__(vertices)
Creates a new vertex component selection from the passed in sequence of hou.Vertex objects.
__init__(edges)
Creates a new edge component selection from the passed in sequence of hou.Edge objects.
freeze()
→ hou.Selection
Returns a copy of the Selection object. This copy can be modified with any of the functions that alter the selection.
invert(geo)
Using the supplied hou.Geometry object for reference, inverts the current selection. The selection will contain only those components that were not in the selection before this method call.
convert(geo, selection_type, select_only_whole=False)
Using the supplied hou.Geometry object for reference, converts the
current selection to the new hou.geometryType. If select_only_whole
is True, select only the edges or primitives that have all their points
selected.
boundary(geo, uv_connectivity = False)
Using the supplied hou.Geometry object for reference, changes the
selection to contain those components on the boundary of the current
selection. The uv_connectivity
parameter controls whether to use
topology or uv attribute values to determine whether components are
connected.
grow(geo, uv_connectivity = False)
Using the supplied hou.Geometry object for reference, adds to the
selection any components connected to the current selection. The
uv_connectivity
parameter controls whether to use topology or uv
attribute values to determine whether components are connected.
shrink(geo, uv_connectivity = False)
Using the supplied hou.Geometry object for reference, removes from
the selection any components on the boundary of the current selection. The
uv_connectivity
parameter controls whether to use topology or uv
attribute values to determine whether components are connected.
combine(geo, selection, modifier)
Using the supplied hou.Geometry object for reference, combines this selection with another.
geo
A hou.Geometry object that is used when doing any selection conversions.
selection
A hou.Selection object that will be combined with the current selection. If this selection does not have the same component type as the current selection, an implicit conversion to the current component type is performed before combining the selections.
modifier
A hou.pickModifier value that controls how the selections will be combined. This lets you perform a union, intersection, or other operation on a pairs of selections.
clear()
Removes all components from the current selection.
selectionType()
Returns a hou.geometryType value indicating the type of component referenced by this selection.
numSelected()
Returns the number of components in the selection.
prims(geo)
→ tuple
of hou.Prim
Returns a tuple of all primitives in the selection. If the selection does not contain primitives, an implicit conversion to primitives is performed to generate the return value.
points(geo)
→ tuple
of hou.Point
Returns a tuple of all points in the selection. If the selection does not contain points, an implicit conversion to points is performed to generate the return value.
vertices(geo)
→ tuple
of hou.Vertex
Returns a tuple of all vertices in the selection. If the selection does not contain vertices, an implicit conversion to vertices is performed to generate the return value.
edges(geo)
→ tuple
of hou.Edge
Returns a tuple of all edges in the selection. If the selection does not contain edges, an implicit conversion to edges is performed to generate the return value.
selectionString(geo, force_numeric = False, collapse_where_possible = True, asterisk_to_select_all = False)
→ str
Returns a string that specifies the selected components. The format of this string is appropriate for use in SOP Group parameter fields.
geo
A hou.Geometry object that is used when generating the selection string (such as determining if all components are selected).
force_numeric
Set this to True
to force the generated string to contain only numeric
ranges, even if the selection was constructed with group or attribute
based selection.
collapse_where_possible
Set this to True
to cause numeric ranges to be collapsed as much as
possible, regardless of the selection order. So for example if the
user selected primitive 3, then 2, then 1, the generated selection
string would either be '3 2 1' or '1-3' depending on this parameter.
asterisk_to_select_all
When this parameter is set to False
, if a selection contains all
components in the supplied geometry, the resulting value is an empty
string. This is appropriate when using the resulting string in a SOP
node Group parameter. If this parameter is set to True
, a full
selection will return a value of '*' instead.