Hi @STECORO. It seems as though the faces of copied 'transient' bodies do not retain the 'appearances' of the original, real bodies, and attempting to access them causes an error. So, the next alternative is to use 'real' geometry techniques similar to the BRep Boolean operation to combine all bodies into one (temporarily), then check face appearances and areas, then 'UNDO' the feature that combined all the bodies again. Below is an example iLogic code doing it that way, utilizing an Inventor.Transaction so that we can 'UNDO' the actions it is doing, and also utilizing a CombineFeature to join all bodies together.
Sub Main
Dim oInvApp As Inventor.Application = ThisApplication
Dim oPDoc As PartDocument = TryCast(ThisDoc.Document, Inventor.PartDocument)
If oPDoc Is Nothing Then Return
Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
Dim oBodies As SurfaceBodies = oPDef.SurfaceBodies
If oBodies.Count = 0 Then Return
Dim oColorsToExclude As New List(Of String)
oColorsToExclude.Add("Steel")
oColorsToExclude.Add("Polished Steel")
Dim oTBody As SurfaceBody = oBodies.Item(1)
Dim dPaintedArea As Double = 0.0
If Not oPDef.HasMultipleSolidBodies Then
dPaintedArea = GetPaintedArea(oTBody, oColorsToExclude)
ElseIf oPDef.HasMultipleSolidBodies Then
Dim oTrans As Inventor.Transaction = oInvApp.TransactionManager.StartTransaction(oPDoc, "Combine Bodies - iLogic")
Dim oCFs As CombineFeatures = oPDef.Features.CombineFeatures
Dim oToolBodies As ObjectCollection = oInvApp.TransientObjects.CreateObjectCollection
For i As Integer = 1 To oBodies.Count
oBody = oBodies.Item(i)
If oBody Is oTBody Then Continue For
oToolBodies.Add(oBody)
Next i
Dim oCF As CombineFeature = oCFs.Add(oTBody, oToolBodies, PartFeatureOperationEnum.kJoinOperation, False)
dPaintedArea = GetPaintedArea(oTBody, oColorsToExclude)
oTrans.Abort
End If
iLogicVb.Automation.ParamValue(oPDoc, "PAINTED_AREA") = CStr(dPaintedArea * 100)
oPDoc.Update2(True)
End Sub
Function GetPaintedArea(oBody As SurfaceBody, oAppearancesToExclude As List(Of String)) As Double
If oBody Is Nothing OrElse oAppearancesToExclude Is Nothing OrElse oAppearancesToExclude.Count = 0 Then Exit Function
Dim dPaintedArea As Double = 0.0
For Each oFace As Face In oBody.Faces
Dim sFaceAppearanceName As String = oFace.Appearance.DisplayName
If oAppearancesToExclude.Contains(sFaceAppearanceName) Then Continue For
Dim dArea As Double = oFace.Evaluator.Area
dPaintedArea += dArea
Next oFace
Return dPaintedArea
End Function
If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.
Wesley Crihfield
(Not an Autodesk Employee)