Hi @ngnam1988. I am not sure if what I think you are asking about is possible to determine by code with that little information, and if it was possible, it would likely require a super long, and very complicated rule. Here is an exploratory rule you can play around with though. It mostly just writes related data to the iLogic Log window for you. It first makes sure we are dealing with a Part, then makes sure it has some bodies, then gets the first body. It reports the body name to the log. Then it gets which generic PartFeature created it, and checks if it was an Extrusion type feature. If so, it reports that feature name to the Log. Then it gets the Profile used to create it, then gets its parent Sketch, and reports the name of the Sketch to the Log. Then it searches for first level SketchBlock objects within that sketch, and writes their names and count to the Log. Then it looks for second level (deeper) SketchBlock objects under the first level ones, and writes their names and count to the Log. And if any second level blocks were found, a message shows the name of the first one. But there is no guarantee that the one being reported is the only SketchBlock being used to create that body.
Sub Main
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then Exit Sub
Dim oPDoc As PartDocument = ThisDoc.Document
Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
Dim oBodies As SurfaceBodies = oPDef.SurfaceBodies
If oBodies.Count = 0 Then Exit Sub
Dim oBody As SurfaceBody = oBodies.Item(1)
If oBody.IsTransient Then Exit Sub
Logger.Info("Body Name = " & oBody.Name)
Dim oFeat As PartFeature = oBody.CreatedByFeature
Dim oFirstLevelBlocks As New List(Of Inventor.SketchBlock)
Dim oSecondLevelBlocks As New List(Of Inventor.SketchBlock)
If oFeat.Type = ObjectTypeEnum.kExtrudeFeatureObject Then
Dim oExtFeat As ExtrudeFeature = oFeat
Logger.Info("Extrude Feature Name = " & oExtFeat.Name)
Dim oProfile As Inventor.Profile = oExtFeat.Definition.Profile
Dim oSketch As Inventor.Sketch = oProfile.Parent
Logger.Info("Sketch Name = " & oSketch.Name)
For Each oEnt As SketchEntity In oSketch.SketchEntities
Dim oBlock1 As SketchBlock = oEnt.ContainingSketchBlock
If oBlock1 IsNot Nothing AndAlso oFirstLevelBlocks.Contains(oBlock1) = False Then
oFirstLevelBlocks.Add(oBlock1)
Logger.Info("First Level SketchBlock Name = " & oBlock1.Name)
End If
Next 'oEnt
Logger.Info("First Level SketchBlocks Count = " & oFirstLevelBlocks.Count)
If oFirstLevelBlocks.Count = 0 Then Exit Sub
For Each oFLBlock In oFirstLevelBlocks
If oFLBlock.ChildBlocks.Count = 0 Then Continue For
For Each oSLBlock As SketchBlock In oFLBlock.ChildBlocks
If oSecondLevelBlocks.Contains(oSLBlock) = False Then
oSecondLevelBlocks.Add(oSLBlock)
Logger.Info("Second Level SketchBlock Name = " & oSLBlock.Name)
End If
Next 'oSLBlock
Next 'oFLBlock
Logger.Info("Second Level SketchBlocks Count = " & oSecondLevelBlocks.Count)
End If 'feature type check
If oSecondLevelBlocks.Count > 0 Then
MsgBox("The name of the first SketchBlock in the second level of SketchBlocks is " & _
oSecondLevelBlocks.First.Name,,"")
End If
End Sub
Wesley Crihfield
(Not an Autodesk Employee)
Thanks for your code @WCrihfield,
It's not return correct my question but it's very helpful. I'm trying understand, and working with some other idea. Thanks,
Can't find what you're looking for? Ask the community or share your knowledge.