by Vladimir Ananyev
let’s consider the part that consists of two equal overlapped bodies:
| + | | = | |
Volume=2cm3 Area=10 cm2 | | Volume=2cm3 Area=10 cm2 | | Expected: Volume=3cm3 Area=14 cm2 |
Expected volume is 3 cm3. But on the Physical property tab I see unexpected values:
It looks like UI ignores bodies overlapping. So the question is how can we calculate the correct values in case of bodies overlapping?
The easiest way is to use TransientBRep API. The following code sample calculates volume and surface area of the transient body that is the result of the Boolean union of the two “real” bodies.
Sub TransientBRep_DoBoolean_Multibody()
'uses TransientBRep to calculate area and volume
'of the two overlapped bodies in the multibody part
Dim oPartDoc As PartDocument
Set oPartDoc = ThisApplication.ActiveDocument
Dim oPartDef As PartComponentDefinition
Set oPartDef = oPartDoc.ComponentDefinition
Dim oRealBody1 As SurfaceBody
Set oRealBody1 = oPartDef.SurfaceBodies.Item(1)
Dim oRealBody2 As SurfaceBody
Set oRealBody2 = oPartDef.SurfaceBodies.Item(2)
Dim oTransientBRep As TransientBRep
Set oTransientBRep = ThisApplication.TransientBRep
Dim oBody1 As SurfaceBody
Set oBody1 = oTransientBRep.Copy(oRealBody1)
Dim oBody2 As SurfaceBody
Set oBody2 = oTransientBRep.Copy(oRealBody2)
'do Boolean operation on the two bodies
'only oBody1 has to be transient
Call oTransientBRep.DoBoolean( _
oBody1, oBody2, BooleanTypeEnum.kBooleanTypeUnion)
'' Call oTransientBRep.DoBoolean( _
'' oBody1, oBody2, BooleanTypeEnum.kBooleanTypeIntersect)
Debug.Print "Volume = " & oBody1.volume(0.001)
Debug.Print "Area = " & GetBodyArea(oBody1)
End Sub
Private Function GetBodyArea(ByRef oBody As SurfaceBody) As Double
Dim area As Double
area = 0
Dim oFace As Face
For Each oFace In oBody.faces
Dim oEval As SurfaceEvaluator
Set oEval = oFace.Evaluator
area = area + oEval.area
Next
GetBodyArea = area
End Function
Results:
If you need to know the volume of the intersections then you should change the type of the Boolean operation to BooleanTypeEnum.kBooleanTypeIntersect.
Results: