Issue
Is there a way to find the corresponding face on the original feature for PatternElement face?
Solution
There is not a straightforward way to get at the original face. Here is an approach to find the face on the original feature:
1. Get a sample point on the pattern element face (Face.PointOnFace property)
2. Find which PatternElement the point belongs to
3. Transform this point to the original occurrence of the pattern (post multiply by the inverse of the transform obtained using FeaturePatternElement.Transform)
4. Use the transformed point in SurfaceBody.LocateUsingPoint method to obtain the original face.
5. Use this original face to get its feature.
Here is a example. Before running this macro select a face from a CircularPatternFeature. (not a face on the original feature) The corresponding face on the original feature, including the original feature will be added to the selectSet.
VB.NET
Private Sub test()
If m_inventorApp.ActiveDocument.DocumentType <>
DocumentTypeEnum.kPartDocumentObject Then
MsgBox("Make a Part Document the active document")
End
End If
Dim oPart As PartDocument = m_inventorApp.ActiveDocument
If oPart.SelectSet.Count < 1 Then
MsgBox(
"Need to select a face of a circular pattern feature")
End
End If
Dim testObj As Object
testObj = oPart.SelectSet(1)
If Not TypeOf testObj Is Face Then
MsgBox("Select a face of a circular patern feature")
End
End If
Dim oSelFace As Face
oSelFace = testObj
Dim oCirPattern As CircularPatternFeature
testObj = oSelFace.CreatedByFeature
If Not TypeOf testObj Is CircularPatternFeature Then
MsgBox(
"Selected face not a face of a circular patern feature")
End
End If
oCirPattern = testObj
Dim oSelFace_PatternElement As FeaturePatternElement
Dim oPatternElement As FeaturePatternElement
Dim oEachFace As Face
For Each oPatternElement In oCirPattern.PatternElements
For Each oEachFace In oPatternElement.Faces
If oEachFace.TransientKey = oSelFace.TransientKey
Then
oSelFace_PatternElement = oPatternElement
Exit For
End If
Next oEachFace
If Not oSelFace_PatternElement Is Nothing Then
Exit For
End If
Next oPatternElement
If Not oSelFace_PatternElement Is Nothing Then
Dim oPtInFace As Point
oPtInFace = oSelFace.PointOnFace
Dim oMatrix As Matrix
oMatrix = oSelFace_PatternElement.Transform
oMatrix.Invert()
Call oPtInFace.TransformBy(oMatrix)
Dim oOrignFace As Face
oOrignFace = oPart.ComponentDefinition.
SurfaceBodies(1).
LocateUsingPoint(ObjectTypeEnum.kFaceObject, oPtInFace)
Call oPart.SelectSet.Select(oOrignFace)
Dim oOriginalF As PartFeature
oOriginalF = oOrignFace.CreatedByFeature
Call oPart.SelectSet.Select(oOriginalF)
End If
End Sub