Count unique bodies in the IAM

Count unique bodies in the IAM

Maxim-CADman77
Advisor Advisor
521 Views
1 Reply
Message 1 of 2

Count unique bodies in the IAM

Maxim-CADman77
Advisor
Advisor

I'm trying to write an iLogic app for processing bodies of the active Assembly.

My minimal goal is just to count unique bodies.

My current best bet is:

Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
Dim MsgBody As String=""
Dim OccIndex As Integer=0
Dim BdQTY As Integer=0

For Each oOcc As ComponentOccurrence In oAsmDoc.ComponentDefinition.Occurrences
BdQTY=BdQTY+oOcc.SurfaceBodies.Count
OccIndex=OccIndex+1
MsgBody=MsgBody & "#" & OccIndex & ":" & vbCrLf & "Name : " & oOcc.Name & vbCrLf & "Type : " & oOcc.Type & vbCrLf & "BodyQTY = " & oOcc.SurfaceBodies.Count  & vbCrLf & vbCrLf
Next
MsgBox(MsgBody,, BdQTY & " bodies found in " & oAsmDoc.ComponentDefinition.Occurrences.Count & " components:")

For standard sample weldment-assembly Carriage.iam it gives me wrong result (6 bodies) while expected is 10 bodies (reported by BSCT after pressing Ctrl+F7) :

AssyBodies.png

I guess I have done at least two mistakes:

1. I am not skipping the body for duplicated occurences 

2. I'm not counting bodies of sub-assemblies

and may be I should more carefully process weld-beads

 

As for 2 if I don't missed some easier way (some ready for use property) i probably need to add some recursion procedure (never did this before yet) , right?

 

Could please somebody point  me in the right direction..

 

PS: My further goal - get body-complexity rating i.e.. report N (let say five) most complex bodies sorted for decreasing FaceCount  

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Accepted solutions (1)
522 Views
1 Reply
Reply (1)
Message 2 of 2

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

@Maxim-CADman77,

 

Hoping that below iLogic code may help to get count of bodies in an assembly.

Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
Dim MsgBody As String=""
Dim OccIndex As Integer=0
Dim BdQTY As Integer=0
Dim oDoc As Document 
For Each oDoc In oAsmDoc.AllReferencedDocuments 
BdQTY=BdQTY+ oDoc.ComponentDefinition.SurfaceBodies.Count
OccIndex=OccIndex+1
MsgBody=MsgBody & "#" & OccIndex & ":" & vbCrLf & "Name : " & oDoc.DisplayName & vbCrLf & "Type : " & oDoc.DocumentType & vbCrLf & "BodyQTY = " & oDoc.ComponentDefinition.SurfaceBodies.Count  & vbCrLf & vbCrLf
Next
MsgBox(MsgBody,, BdQTY & " bodies found in " & oAsmDoc.ComponentDefinition.Occurrences.Count & " components:")

Count bodies.PNG

 

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes