tracking number of surface in python scripting.

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
imanipourmeysam
Posts: 23
Joined: Thu Nov 18, 2021 2:41 pm

tracking number of surface in python scripting.

Post by imanipourmeysam »

Hello.
I want to have a track of the numbers of surfaces by using python scripting.
For example, if I have a cube then I will have 6 surfaces or if I have a cylinder then I will have 3 surfaces.
Do you have any idea of how I can calculate the number of surfaces in a model ?
Thank you.
User avatar
Chris_G
Veteran
Posts: 2598
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: tracking number of surface in python scripting.

Post by Chris_G »

You can copy / paste this in the python console :

Code: Select all

total = 0
for obj in App.activeDocument().Objects:
    if hasattr(obj, "Shape"):
        print(f"Object {obj.Label} has {len(obj.Shape.Faces)} faces")
        total += len(obj.Shape.Faces)

print(f"Document has a total of {total} faces")
Post Reply