Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Count unique bodies in the IAM

1 REPLY 1
SOLVED
Reply
Message 1 of 2
Maxim-CADman77
474 Views, 1 Reply

Count unique bodies in the IAM

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  

1 REPLY 1
Message 2 of 2

@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



Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report