Get wall face areas in Python

Hi,
I am trying to get the area of wall faces inside Python script.
The input for Python node are all walls instances selected by Dynamo nodes.
In Python script I retrieve geometry (solids) of each wall instance.
Then I get faces of each solid.
What I want to do is get the area of each face of each wall.
However, I keep getting an error: ‘Face’ object has no attribute ‘Area’.
Revit API states that the Face class has an “Area” property, so I don’t know what I’m doing wrong here.
I would appreciate any help a lot.

import clr

clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

clr.AddReference("RevitNodes")
import Revit

clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

from Revit.Elements import *

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import *
import sys

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
adoc = doc.ActiveView

wallsWrapped = IN[0]

OUT = []
wallsGeometry = []
wallFaces = []
wallFacesAreas = []

for w in wallsWrapped:
    wallsGeometry.append(w.Geometry()[0])

for i in wallsGeometry:
    wallFaces = i.Faces
    for singleFace in wallFaces:
        wallFacesAreas.append(singleFace.Area)

OUT = wallFaces, wallFacesAreas

Hi, I am not sure the way you extract geometry is correct…

Maybe something like this would work: (just keep in mind the units)

import clr

#The inputs to this node will be stored as a list in the IN variables.
walls = UnwrapElement(IN[0])

clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *


options = Options()
#options.ComputeReferences = True
#options.IncludeNonVisibleObjects = True



faces = []
faceAreas = []

#get side references
for w in walls:
  geoElement = w.get_Geometry(options)
  for obj in geoElement:
    if isinstance(obj,Solid):
      for f in obj.Faces:
        faces.append(f)
        faceAreas.append(f.Area)
      
    

#Assign your output to the OUT variable.
OUT = faces, faceAreas

2 Likes

I think you’re actually using the methods inherited from Autodesk.DesignScript.Geometry instead of Autodesk.Revit.DB

Thanks for a quick reply! Indeed it works fine now.

My way of extracting geometry gave me the list of faces so I assumed that this would be correct geometry.


Now I know it doesn’t work like this.
Thank you a lot.

2 Likes