Is it possible to obtain the feature instances by picking an edge in an Inventor drawing view? That is, I have an .idw with a view of a part. If I pick an edge, can I tell what feature(s) that edge belongs to? Yes, the following sample code finds all features that contain the edge selected by the user:
Public Sub queryFeaturesFromEdge()
Dim oDoc As DrawingDocument = m_inventorApplication.ActiveDocument
If oDoc.SelectSet.Count <> 1 Then
MsgBox("Please select a single curve segment!")
Exit Sub
End If
Dim selectedEntity As Object = oDoc.SelectSet.Item(1)
If (selectedEntity.Type <> _
ObjectTypeEnum.kDrawingCurveSegmentObject) Then
MsgBox("Please select a single curve segment!")
Exit Sub
End If
Dim curve As DrawingCurveSegment = selectedEntity
Dim allFeatures As New System.Collections. _
Generic.List(Of PartFeature)
'Collect all features that contains the selected edge
If curve.Parent.ModelGeometry.Type = _
ObjectTypeEnum.kEdgeObject Then
Dim oEdge As Edge = curve.Parent.ModelGeometry
For Each face As Face In oEdge.Faces
If Not allFeatures.Contains(face.CreatedByFeature) Then
allFeatures.Add(face.CreatedByFeature)
End If
Next
ElseIf (curve.Parent.ModelGeometry.Type = _
ObjectTypeEnum.kFaceObject) Then
Dim face As Face = curve.Parent.ModelGeometry
If Not allFeatures.Contains(face.CreatedByFeature) Then
allFeatures.Add(face.CreatedByFeature)
End If
End If
'print some information of the features
Debug.Print(
"The selected edge is contained by the following features:")
For Each feature As PartFeature In allFeatures
Debug.Print(feature.Name)
Next
End Sub