Material of a Face

Hi! I’m trying to make a python script node that would ingest elements, and return their Faces Material

These elements are painted in Revit, and I would like to check with what kind of materials they were
painted with.

I am using method from this topic but it returns this error:

What am I doing wrong here?

@filip.kabelis try it like this:
P.S.: pasting your code in here save us the trouble of rewriting it.

elem = UnwrapElement(IN[0])

x = []

gOpts = Options()

geom = elem.get_Geometry(gOpts)
for j in geom:
	face = j.Faces
	for f in face:
		eId = f.MaterialElementId
		mat = doc.GetElement(eId).Name
		x.append(mat)
			
OUT = x

This still won’t work. It returns this error for me

AttributeError: ‘GeometryInstance’ object has no attribute ‘Faces’

I tried approach with “get_Geometry” and then using GetInstanceGeometry or GetSymbolGeometry, but then I would also receive error "no attribute ‘Faces’ " even if output of GetInstanceGeometry would be Autodesk.Revit.DB.Solid (which in API has property ‘Faces’…)

Just to add to it - i’m feeding this code with a Column type family consisting of couple of simple extrusions and 1 nested family also with extrusions only - so nothing that would prevent reading Faces normally.

Just to add to it - I have 3 different codes for this task, here are they below with errors that i’m stuck on.

So this one returns

AttributeError: ‘Face’ object has no attribute ‘MaterialElementId’

x = []

for i in IN[0].Faces:
	x.append(i)
	srf = UnwrapElement(x)
	faces = []
	for e in srf:
		faces.append(e.Faces)
		for f in faces:
			for fac in f:
				elementId = fac.MaterialElementId
				mat = doc.GetElement(elementId).Name

And this one returns

AttributeError: ‘GeometryInstance’ object has no attribute ‘Faces’

elem = UnwrapElement(IN[0])

x = []

gOpts = Options()

geom = elem.get_Geometry(gOpts)
for j in geom:
	face = j.Faces
	for f in face:
		eId = f.MaterialElementId
		mat = doc.GetElement(eId).Name
		x.append(mat)
			
OUT = x

And last one returns

AttributeError: ‘list’ object has no attribute ‘MaterialElementId’

x = []

for i in IN[0].Faces:
	x.append(i)
	srf = UnwrapElement(x)
	faces = []
	for e in srf:
		faces.append(e.Faces)


elementlist = list()

for face in UnwrapElement(faces):
	try:
		ref = face.Tags.LookupTag("RevitFaceReference")
		face = doc.GetElement(ref).GetGeometryObjectFromReference(ref)
		elementlist.append(face)
	except:
		elementlist.append(list())
		
for c in elementlist:
	c.MaterialElementId()
	mat.append(c)




OUT = mat

@filip.kabelis can you share the family?

It doesn’t even work on this type of family you see below, nothing really to share its just single extrusion in Column category :confused:

Shot in the dark here: Try removing the designscript geometry import - lines 2 and 3 in your first screenshot.

@filip.kabelis you just need to get rid of the extra elements, such as the Geometry Instance and the Analytical Model, if you check a structural column family using the Revit Lookup, it shows where the appropriate Solid element is buried, maybe a conditional to get rid of the geometry instance and the empty solid would be better than getting the right solid by index:

1 Like

@jacob.small - removing DScript geometry did not help

@Elie.Trad - Bingo! These aren’t Structural Columns so no need filtering out the analytical model, but pointing the right index in loop looking for material IDs finally returned valid results :slight_smile:

thank you all guys, case closed

PS. I have a question - what does gOpts = Options() actually do in this code?

1 Like

@filip.kabelis I guess it give access to the geometry of the elements: