How to find if a parent feature in a pattern is a hole feature.

How to find if a parent feature in a pattern is a hole feature.

matthew.tannerAA4QB
Explorer Explorer
179 Views
1 Reply
Message 1 of 2

How to find if a parent feature in a pattern is a hole feature.

matthew.tannerAA4QB
Explorer
Explorer

Below is a snip of the code I am writing.

I am looking to separate pattern that uses a hole feature as the parent from other pattern features.

      Dim RectFeat As RectangularPatternFeature = DirectCast(feat, RectangularPatternFeature)
            
            ' Check if the pattern feature is a hole pattern
            Dim kHoleFeatureObject As Inventor.ObjectTypeEnum = Inventor.ObjectTypeEnum.kHoleFeatureObject
            If RectFeat.Definition.AffectedBodies.Type = kHoleFeatureObject Then
                Dim holePattern As HoleFeature = DirectCast(RectFeat.PatternFeatureDefinition.ParentFeatures, HoleFeature)
                Dim holeSideFaces As Faces = holePattern.Faces
                Dim i As Integer = 1
                
                For Each holeSideFace As Face In holeSideFaces
                    Dim iMateDef As InsertiMateDefinition = CompDef.iMateDefinitions.AddInsertiMateDefinition(holeSideFace, True, 0, , featName & "-" & i)
                    i = i + 1 
                Next
            End If


Any help or advice would be much appreciated thank you.
 

0 Likes
180 Views
1 Reply
Reply (1)
Message 2 of 2

WCrihfield
Mentor
Mentor

Hi @matthew.tannerAA4QB.  The first problem point in your code is in this line:

If RectFeat.Definition.AffectedBodies.Type = kHoleFeatureObject Then

The RectangularPatternFeatureDefinition.AffectedBodies property returns an ObjectCollection.  The ObjectTypeEnum variation for that would always be kObjectCollectionObject.  And the objects within that collection are supposed to be SurfaceBody type objects, not features, so even testing the first item in the collection would not return a HoleFeature object.  Then in the next line of code:

Dim holePattern As HoleFeature = DirectCast(RectFeat.PatternFeatureDefinition.ParentFeatures, HoleFeature)

...you are using RectFeat.PatternFeatureDefinition, instead of just RectFeat.Definition, in one area of it.  Then RectangularPatternFeatureDefinition.ParentFeatures property returns another ObjectCollection, not a single feature.  You could try using the first item found within the collection, but no guarantees.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes