Get the parent of a feature created from a patterned occurance

Get the parent of a feature created from a patterned occurance

Anonymous
Not applicable
761 Views
3 Replies
Message 1 of 4

Get the parent of a feature created from a patterned occurance

Anonymous
Not applicable

Hi Autodesk Community!

 

I would like to get the feature that a patterned feature was created from. For example, considered two hole features patterned with the circular tool. For each hole in each occurance of the pattern I need to get the corresponding hole feature that created that.

 

The only way I have found so far is to get the ParentFeatures of the CircularPatternFeature. Although, if there is more than one parent feature, I cannot work out a way choose the correct parent. 

 

Would greatly appreaciate a solution for this problem!

 

Best,

Aaron

0 Likes
Accepted solutions (1)
762 Views
3 Replies
Replies (3)
Message 2 of 4

ekinsb
Alumni
Alumni
Accepted solution

This is a bit tricky because the pattern result isn't a set of features but is instead several occurrences of faces that have been applied to a body.  I created the example that you described and the result is what you see below.  The two hole features were used as input but the result is six pattern occurrences where in this case each occurrence contains the two cylindrical faces, (one for each hole).  There aren't any hole features in the pattern result.

 

pattern.png

 

However, assuming you don't really care about having hole features in the result but have a cylindrical face that you know represents a hole and now want to find out what input feature this face corresponds with I think you can do that.

 

Public Sub FindPatternFeature()
    ' Get the active part.
    Dim partDoc As PartDocument
    Set partDoc = ThisApplication.ActiveDocument
    
    ' Have a face selected.
    Dim selectedFace As Face
    Set selectedFace = ThisApplication.CommandManager.Pick(kPartFaceFilter, "Pick the face in the pattern.")
    
    ' Get the feature that created this feature, which should be a circular pattern.
    Dim circPattern As CircularPatternFeature
    Set circPattern = selectedFace.CreatedByFeature
    
    ' Determine which pattern element this face is part of.
    Dim element As FeaturePatternElement
    Dim foundElem As FeaturePatternElement
    For Each element In circPattern.PatternElements
        Dim elemFace As Face
        For Each elemFace In element.Faces
            If elemFace Is selectedFace Then
                Set foundElem = element
                Exit For
            End If
        Next
        
        If Not foundElem Is Nothing Then
            Exit For
        End If
    Next
    
    If Not foundElem Is Nothing Then
        ' Get the transform of the pattern element.
        ' This defines the tranform from the original
        ' entity to this element.
        Dim elemTransform As Matrix
        Set elemTransform = foundElem.Transform
        
        ' Invert the transform to go from the element to
        ' the orginal entity.
        elemTransform.Invert
        
        ' Transform a point on the selected face which should
        ' result in a point that lies on the original corresponding face.
        Dim entPoint As Point
        Set entPoint = selectedFace.PointOnFace
        Call partDoc.ComponentDefinition.WorkPoints.AddFixed(entPoint)
        Call entPoint.TransformBy(elemTransform)
        Call partDoc.ComponentDefinition.WorkPoints.AddFixed(entPoint)
        
        ' Use this point to find the face.
        Dim filter(0) As SelectionFilterEnum
        filter(0) = kPartFaceFilter
        Dim foundFaces As ObjectsEnumerator
        Set foundFaces = partDoc.ComponentDefinition.FindUsingPoint(entPoint, filter, 0.001)
        
        If foundFaces.Count = 1 Then
            Dim originalFace As Face
            Set originalFace = foundFaces.Item(1)
            
            MsgBox "The original feature is " & originalFace.CreatedByFeature.name
        End If
    End If
End Sub

 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 3 of 4

Anonymous
Not applicable

Thanks for the reply and the code!

 

I needed a solution starting from an occurance face, so this code does what I need it to! Thank you! 

 

It would great if the access this provides is built into the API in a future release to save such workarounds.

 

Best,

Aaron

0 Likes
Message 4 of 4

Anonymous
Not applicable

Hi,

I have a question that relates to this discussion.

For a picked face, I would like to if the face has been created by a hole feature or not. Obviously, I can use but CreatedByFeature property, but this proeprty doesn't work when a face is used by patterning a hole. So, for example if we pattern a hole and an extrude together and user pick a face that is created by pattern, should I use the same algorithm that was just explained.

The most coplicated case  might be like, there is a hole that is patterend, then the pattern got mirrored, then the whole part is refrenced to another file, ...

At the end, if we create a drawing and put hole call-out, Inventor knows that the selected surface is a hole. For the threaded faces, it is very clear as there is ThreadInfo property for all the threaded faces on all the patterened faces.

Does inventor save the property of the holw on faces as well? Or does Inventor use the same concept that you explained to track down and find out the hole spec?

 

Patterend features

Patterned hole in drawings

 

 

0 Likes