How can I calculate the total surface area of an object? (and optionally exclude some planes)

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
Post Reply
Mr.T
Posts: 5
Joined: Thu Sep 24, 2015 6:43 pm

How can I calculate the total surface area of an object? (and optionally exclude some planes)

Post by Mr.T »

Hi,

I would like to calculate the total surface area of a part.

I know I can use the survey tool.
However, this require me to select each face manually.
Is there perhaps an easy way to select all faces to get the total surface area?

In addition, I would also like to be able to exclude faces intersecting certain planes (in the attached file, basically the "external faces of the cube") in the surface calculation.
But first, I am just trying to get the total surface area.

I am also happy with any python scripting solutions, if there are any.
Attachments
woodpile_cubic_unit_cell.FCStd
(174.03 KiB) Downloaded 25 times
Syres
Veteran
Posts: 2893
Joined: Thu Aug 09, 2018 11:14 am

Re: How can I calculate the total surface area of an object? (and optionally exclude some planes)

Post by Syres »

Hopefully this covers what you need with the excluding of certain faces. The procedure using your file is click on Common and run the macro. The code as you see (Line Number 5) is excluding Face1 which you'd have to amend with a line for each face to be excluded. It gives you the total surface area of the object selected and with the excluded faces.

Code: Select all

import Part
s = Gui.Selection.getSelectionEx()
# ******* Add the Faces to be excluded ********
excludedReferenceList = []
excludedReferenceList.append((s[0].Object.Name, 'Face1'))
# *********************************************
referenceList = []
component = FreeCAD.ActiveDocument.getObject(s[0].Object.Name)
nFaceArea = 0
for j, g in enumerate(excludedReferenceList):
    for i, f in enumerate(component.Shape.Faces):
        testFace = "('"+str(s[0].Object.Name)+"', '"+"Face{}".format(i+1)+"')"
        if str(g) != testFace:
            nFaceName = 'Face{}'.format(i+1)
            referenceList.append((s[0].Object.Name, 'Face{}'.format(i+1)))
            nFaceArea =+ nFaceArea + component.Shape.Faces[i].Area
print('Total Surface Area of '+str(s[0].Object.Label)+' is '+str(component.Shape.Area)+' mm^2')
# print('Total number of faces in '+str(s[0].Object.Label)+' is '+str(i+1))
print('Total Surface Area of '+str(s[0].Object.Label)+' minus excluded faces is '+str(nFaceArea)+' mm^2')
Tested using:

Code: Select all

OS: Windows 7 Version 6.1 (Build 7601: SP 1)
Word size of FreeCAD: 64-bit
Version: 0.20.29177 (Git)
Build type: Release
Branch: releases/FreeCAD-0-20
Hash: 68e337670e227889217652ddac593c93b5e8dc94
Python 3.8.10, Qt 5.15.2, Coin 4.0.1, Vtk 8.2.0, OCC 7.6.2
Locale: English/United Kingdom (en_GB)
Installed mods: 
  * A2plus 0.4.56a
  * CfdOF 1.17.4
  * Curves 0.5.1
  * fasteners 0.3.50
  * fcgear 1.0.0
  * freecad.xray 2022.4.17
  * Manipulator 1.4.9
  * Plot 2022.4.17
  * sheetmetal 0.2.55
  * Silk 1.0.0
Mr.T
Posts: 5
Joined: Thu Sep 24, 2015 6:43 pm

Re: How can I calculate the total surface area of an object? (and optionally exclude some planes)

Post by Mr.T »

Thank you! I tried all three methods. (That FCInfo script looks really powerful!)

Now I am just trying to figure out how to automate/semi-automate face selection and combine it with @Syres script.
tino
Posts: 51
Joined: Sun Mar 24, 2019 6:40 pm
Location: Altstätten
Contact:

Re: How can I calculate the total surface area of an object? (and optionally exclude some planes)

Post by tino »

Hello, how can I find the path where FCInfo Macro safes the Spreadsheet in Freecad 20.1
Post Reply