CATIA V5 Exporting Surface Area Using VBA

Hi all

 

I have a macro that I have created, that exports to a spreadsheet a list of every part in a product, showing the part number, description, material, volume, CoG and surface area.

I'm getting the volume (which isn't available to export from the inertia data it seems) by using the mass and density of each part, both of which are accessible as oInertia.mass and oInertia.density. The resultant output is accurate, and returns the same value as if I manually measure the inertia in an individual part.

However just like the volume, the area is not accessible from the inertia data, for some reason. I don't really know VBA, and a lot of my macros are constructed with a lot of trial and error and internet searches, however I did find the following code that uses the SPAWorkbench and outputs area data to my spreadsheet:

Dim spaWB As Workbench
       Set spaWB = CATIA.ActiveDocument.GetWorkbench("SPAWorkbench")

       Dim body As body
       Dim measurable As measurable
       Dim ref As Reference
       Dim shape As shape
       area = 0

       For Each body In partDef.Bodies
           If body.IsGeometricalSet = False Then ' Only consider solid bodies
               Set shape = body.Shapes.Item(1) ' Assume the first shape is the solid (often valid)
               If Not shape Is Nothing Then
                   Set ref = partDef.CreateReferenceFromObject(shape)
                   Set measurable = spaWB.GetMeasurable(ref)
                   If Not measurable Is Nothing Then
                       area = area + measurable.area
                   End If
               End If
           End If
       Next

But the weird thing is that these outputs aren't at all accurate, and not by a constant margin either. One part will output an area barely one tenth of the actual measured area, while another will be 98% of the actual figure. But none are completely accurate.

Does anyone have an idea why these exported area measurements are so widely inaccurate? And does anyone know of a better and more reliable way to export the surface area of parts in a macro?