foreach (Entity ent in design1.Entities)
{
if (ent.Selected)
{
Since Eyeshot version 1, entity selection was controlled by Entity.Selected property. The first evolution happened in Eyeshot version 9, where we introduced the ability to select object sub-items, like vertices, edges or faces (see the selectionFilterType enum). Even this new feature, by the way, did not resolve the ability to select items inside a specific assembly component instance. A real-world example could be a mechanical part with many instances of the same bolt on it, where you pretend to select a face of a specific bolt instance. This is the reason why in Eyeshot version 10 we invite all of our customers to get familiar with the following new selection API.
Entity
Entity.SetSelection(status, Stack<BlockReference> parents = null)
Entity.GetSelection(Stack<BlockReference> parents = null)
Entity.ClearSelectionForAllInstances() // clears entity selection for all instances
When the parents parameter is omitted, you select the actual entity (top level, no block/block reference involved). When the parents parameter is used with a chain of parents instead, you select the entity inside the specified block reference instance. The same applies to the sub-items selection below.
Faces (Brep/Mesh/Solid)
SetFaceSelection(faceIndex, status, Stack<BlockReference> parents = null)
GetFaceSelection (faceIndex, Stack<BlockReference> parents = null)
ClearFacesSelection(Stack<BlockReference> parents = null) // clears faces selection for top level or nested instance
ClearFacesSelectionForAllInstances() // clears faces selection (for all shells) for all instances
Please note that Mesh and Solid faces can be selected only interactively.
Edges (Brep only)
Brep.SetEdgeSelection(edgeIndex, status, Stack<BlockReference> parents = null)
Brep.GetEdgeSelection(edgeIndex, Stack<BlockReference> parents = null)
Brep.ClearEdgesSelection(Stack<BlockReference> parents = null) // clears edges selection for top level or nested instance
Brep.ClearEdgesSelectionForAllInstances() // clears edges selection for all instances
Vertices (Brep only)
Brep.SetVertexSelection(vertexIndex, status, Stack<BlockReference> parents = null)
Brep.GetVertexSelection(vertexIndex, Stack<BlockReference> parents = null)
Brep.ClearVerticesSelection(Stack<BlockReference> parents = null) // Clears vertices selection for top level or nested instance
Brep.ClearVerticesSelectionForAllInstances() // Clears vertices selection for all instances
Assembly Selection Mode
When you are dealing with a scene graph or an assembly of components, another selection option is available: branch or leaf (see assemblySelectionType enum). The former option allows the selection of the specified component instance and all its children. The latter allows the selection of a single component at the bottom of the chain.
You can experiment with these options in the AssemblyBrowser source code sample.
SelectionChanged Event
When listening to Design.SelectionChanged event, it is possible to get the information about the selected Entity/Face/Edge/Vertex in the following way:
private void design1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Console.WriteLine("--- Added items");
foreach (SelectedItem si in e.AddedItems)
{
PrintItem(si);
}
Console.WriteLine("--- Removed items");
foreach (SelectedItem si in e.RemovedItems)
{
PrintItem(si);
}
}
private static void PrintItem(SelectedItem sItem)
{
Console.WriteLine("Parents: ");
foreach (BlockReference parent in sItem.Parents)
{
Console.WriteLine(parent);
}
if (sItem is SelectedSubItem)
{
if (sItem is SelectedFace selectedFace)
{
Console.WriteLine("ShellIndex: " + selectedFace.ShellIndex);
Console.WriteLine("Face: " + selectedFace.Index);
}
else if (sItem is SelectedEdge selectedEdge)
{
Console.WriteLine("Edge: " + selectedEdge.Index);
}
else if (sItem is SelectedVertex selectedVertex)
{
Console.WriteLine("Vertex: " + selectedVertex.Index);
}
}
}
Selection Modes
Let's close this article by doing a quick recap of available selection modes. Please note that sub-item selection is available only for graphical selection modes.
Geometrical
SelectByPick | Entity selection by pick. A single random item crossing the pick box. |
SelectByBox | Entity selection by box. All items crossing the selection box. |
SelectByBoxEnclosed | Entity selection by box on enclosed items only. All items entirely enclosed in the selection box. |
SelectByPolygon | Entity selection by polygon. All items crossing the selection polygon. |
SelectByPolygonEnclosed | Entity selection by polygon on enclosed only. All items entirely enclosed in the selection polygon. |
Graphical
SelectVisibleByPick | Entity selection by pick on visible only. The single item (closest to the user) crossing the pick box. |
SelectVisibleByBox |
Entity selection by box on visible only. All items (closest to the user) crossing the selection box. |
SelectVisibleByPolygon | Entity selection by polygon on visible only. All items (closest to the user) crossing the selection polygon. |
SelectVisibleByPickDynamic | Entity selection by pick on visible only. The single item (closest to the user) crossing the pick box. Performed dynamically during the mouse movement. |
As you can imagine setting Entity.Selected as true for a block definition entities does not make much sense with assemblies of components. It will result in the selection of the same entity in each block instance of the 3D scene.
Comments
I Try to select a single edge within a composite curve.
Is there any way to do this, or do I have to add each sub element from the composition curve one by one to the view port?
Hi Stefan,
Sub-item selection on composite curves is not supported, sorry.
Hi,
how to get normal vector of selectedFace?
If you are talking about Brep.Face, you simply need to check if the Brep.Face.Surface is a PlanarSurf type and if it is, check the Plane Z axis.
Hi Alberto
If I set Entity.SetSelection(status, Stack<BlockReference> parents = null) the SelectionChanged of the workspace/design is never triggered?
I have tried different types of assemblySelectionType enum and other selection enums combinations, but the SelectionChanged event is never triggered from code?
Also not in the AssemblyDemo ?
How can I manually change selection from code (tree view), so its basically the same as the user click in the view, and the SelectionChanged event is raised?
Hi Alberto,
I've got exactly the same problem as Guido van Hilst. The SelectionChanged event is never triggered when using Entity.SetSelection. Any update on this?
Thx in advance.
This is by design, there is no reason to raise an event for a method you are calling by yourself. Instead of subscribing to the event, just directly call the event handler method.
Please sign in to leave a comment.