- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
Solved! Go to Solution.