RectangularPatternFeature running me around in circles

RectangularPatternFeature running me around in circles

lando7189
Advocate Advocate
642 Views
2 Replies
Message 1 of 3

RectangularPatternFeature running me around in circles

lando7189
Advocate
Advocate

Hello,

 

I have an Inventor Assembly consisting of 6 'parts', and those 'parts' consists of multiple solid bodies.  I need to extract all of the solid bodies, including those used in FeaturePatterns, so I am writing some code in VB.NET to 'explode' these patterns by getting the solid body and getting the 'CreatedByFeature' to get the original extrusion and create a new sketch and extruding a new solid body in place of each member of the pattern (except the first).  It all works good until i hit the condition below.

 

I have 2 RectangularPatternFeatures that are running me around in circles, and cannot get the the 'CreatedByFeature' to get the source SurfaceBody.

 

I have attached a screenshot of my AssemblyTree (i created this to help me iterate thru the model).  The problem lies in "Rectangular Pattern1" and "Rectangular Pattern 3", they both tell me that the SurfaceBody used is "Stud_J3", but SurfaceBody "Stud_J3" just tells me that it is created by "Rectangular Pattern1".  The other RectangularPatternFeatures use "Stud_J2" & "Stud_J1" and can easily find them.

 

To recreate, just create a new part file and create 2 solid bodies.  Pattern each of them.  Then create a third pattern from one of the elements of the pattern.  Do not use the option to create individual bodies.

 

Perhaps I am just better off telling engineering to always have the 'create new bodies' box marked when they create these pattern!  😛

 

Below is the code that i'm trying to write to to this:

 

 

 

    Public Function ExplodeRectangularPatternFeature(part As PartDocument, Pattern As RectangularPatternFeature, Optional DoDelete As Boolean = True) As Boolean
        On Error Resume Next
        Dim i As Integer
        For Each element As FeaturePatternElement In Pattern.PatternElements
            If TypeOf Pattern.SurfaceBodies.Item(1).CreatedByFeature Is ExtrudeFeature Then
                If element.Transform.Translation.Length > 0 Then

                    '''' andalso not element.suppressed  ''??

                    Dim SourceExtrusion As ExtrudeFeature = Pattern.SurfaceBody.CreatedByFeature
                    Dim ExtDef As ExtrudeDefinition
                    ExtDef = SourceExtrusion.Definition.Copy
                    Dim NewExtrusion As ExtrudeFeature = part.ComponentDefinition.Features.ExtrudeFeatures.Add(ExtDef)

                    Dim ObjColOccurences As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection

                    Dim sb As SurfaceBody = NewExtrusion.SurfaceBodies.Item(1)

                    sb.Name = Pattern.SurfaceBodies.Item(1).Name & "_Copy_#" & element.Index

                    ObjColOccurences.Add(sb)
                    Dim MoveDef As MoveDefinition = part.ComponentDefinition.Features.MoveFeatures.CreateMoveDefinition(ObjColOccurences)

                    Dim FreeDrag As FreeDragMoveOperation
                    FreeDrag = MoveDef.AddFreeDrag(element.Transform.Translation.X, element.Transform.Translation.Y, element.Transform.Translation.Z)

                    Dim mf As MoveFeature = part.ComponentDefinition.Features.MoveFeatures.Add(MoveDef)

                    If sb IsNot Nothing Then
                        i += 1
                    End If
                End If

            ElseIf TypeOf Pattern.SurfaceBody.CreatedByFeature Is RectangularPatternFeature Then
                ' -- if continued, this currently causes a recursive loop
                'For Each pf As PartFeature In Pattern.SurfaceBodies.Item(1).AffectedByFeatures
                '    If pf IsNot Pattern Then
                '        If TypeOf pf Is RectangularPatternFeature Then
                '            ExplodeRectangularPatternFeature(part, pf, DoDelete)
                '        End If
                '    End If
                'Next
            ElseIf TypeOf Pattern.SurfaceBody.CreatedByFeature Is CircularPatternFeature Then

            End If

        Next
        If DoDelete AndAlso i > 0 Then
            Pattern.Delete()
        End If
        Return i > 0
    End Function

 

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

adam.nagy
Autodesk Support
Autodesk Support
Accepted solution

Hi,

 

You don't need two surface bodies to start off.

I created an extrude, then used the created body to make a rectangular pattern with the "New Bodies" option. I then used the created Solid4 to make rectangular pattern with "Join" option. So I still had 4 bodies.

 

I think what you found is correct, since (in my case) Solid4 is affected by both Pattern1 and Pattern2. Pattern one created the box in the first place, then Pattern2 turned it into 4 boxes:

 

RectangularPattern.png

 

 

In your code you seem to be using "Pattern.SurfaceBodies.Item(1)" and "Pattern.SurfaceBody" interchangeably, but they are not the same. The former is the first surface body created by the pattern, the latter is the body that was used by the pattern to create the other bodies.

 

Also, I'm not sure why you are iterating "AffectedByFeatures" when you already know the pattern feature that the surface body was created by. 

So you could just call ExplodeRectangularPatternFeature(part, pf, DoDelete) directly from the relevant ElseIf.

 

Cheers,



Adam Nagy
Autodesk Platform Services
0 Likes
Message 3 of 3

lando7189
Advocate
Advocate

Thanks.  I did not know that the .SurfaceBodies.item(1) & .SurfaceBody could not be used interchangeably.  That may explain a few other issues that I have came across over the years.  Thank you for the reply to my 3 year old post!

 

Happy New Year!

0 Likes