Get all elements in view and count Polygones(faces)

Hello,

I try to find a solution to count polygones of Elements.


easiest way is just select all elements in a 3D-View. But i is timecosuming.

import clr

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

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *

clr.AddReference('System')
from System.Collections.Generic import List

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

#Preparing input from dynamo to revit
element = UnwrapElement(IN[0])

#Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)

#Get Elements of the FamilyInstance Class and by Built-In Category of StructuralFraming in Active View only...
elems = FilteredElementCollector(doc, doc.ActiveView.Id).OfClass(FamilyInstance).OfCategory(BuiltInCategory.OST_StructuralFraming).WhereElementIsNotElementType().ToElements()


TransactionManager.Instance.TransactionTaskDone()

OUT = elems

Next way: how can i modifie my Elementcollector that he collects all elements in view?

I count by faces, is this correct? or is there a option poligons, meshes,… ?

I want to to do some prequality issues before i write a .ifc

KR

Andreas

i think it should work like this except some element cannot be converted in this way to geometry. you may try it

2 Likes

But i have to do it, one by one category. Ok Thank you

The filtered element collector you are using runs on the active view per this portion of your code FilteredElementCollector(doc, doc.ActiveView.Id). If you want it to run on another view, change doc.ActiveView.Id to a new input view’s id. So add a new line for the input of the view, something like targetView = UnwrapElement(IN[1])
and change the doc.ActiveView.Id to targetView.Id and see if that clears things up.

Element.Faces will get all the faces of most elements, reducing the compute load over what you would get from Element.Solids > Geometry.Explode. I am not sure if it will graph mesh faces or not so test that carefully.

3 Likes

Hi,
a face can have several triangles, here is an example counting MeshTriangles on faces

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

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

clr.AddReference('System')
from System.Collections.Generic import List

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

#Preparing input from dynamo to revit
currView = UnwrapElement(IN[0])

opt = Options()
#Get Elements of the FamilyInstance Class and by Built-In Category of StructuralFraming in Active View only...
elems = FilteredElementCollector(doc, currView.Id).OfClass(FamilyInstance).OfCategory(BuiltInCategory.OST_StructuralFraming).WhereElementIsNotElementType().ToElements()

total_triangles = []

for e in elems:
	typeId = e.GetTypeId()
	opt.View = currView
	geoSet = e.get_Geometry(opt)
	for g in geoSet:
		if isinstance(g, Solid) and g.Faces.Size > 0:
			nbrtriangle = sum([f.Triangulate().NumTriangles for f in g.Faces if f.Triangulate() is not None])
			total_triangles.append(nbrtriangle)

		elif isinstance(g, GeometryInstance):
			for instObj in g.SymbolGeometry:
				if isinstance(instObj, Solid) and instObj.Faces.Size > 0:
					nbrtriangle = sum([f.Triangulate().NumTriangles for f in instObj.Faces if f.Triangulate() is not None])
					total_triangles.append(nbrtriangle)
		else:
			pass
	geoSet.Dispose()


total_triangles = sum(total_triangles)

OUT = "{} MeshTriangles for {} Elements".format(total_triangles, elems.Count)
1 Like