↑top

FreeCAD: How to calculate a volume, surface area and gravity center of a shape?

FreeCAD 0.19
  1. Select [View]-[Panels]-[Python console] from the menu to display the "Python console". We will enter commands into this "Python console".

  2. First, we need to get the object we want to measure. You can use the following command to get it by the name displayed in the model tree (= label).

    target_object=App.ActiveDocument.getObjectsByLabel("The object label")[0]

    Fig. The object label
    The object label
  3. Then execute the following commands to display the each values in the "Python console".

    • If you want to get the surface area:

      target_object.Shape.Area

    • If you want to get the volume:

      target_object.Shape.Volume

    • If you want to get the center of mass:

      target_object.Shape.CenterOfMass

  4. Note: if the ShapeType of the shape is "Compound", the center of mass cannot be gotten in this way. To check the ShapeType of a shape, execute the following command.

    target_object.Shape.ShapeType

    In the case of "Compound", you can use Shape.Solids to get the center of mass of the shape's component solids.

    target_object.Shape.Solids[0].CenterOfMass
    target_object.Shape.Solids[1].CenterOfMass
    ...

Fig. Python console
Python console

References