Autodesk.Revit.DB.PlanarFace to Face

Hi, all

how to convert Autodesk.Revit.DB.PlanarFace to Face in python.

Helps if you provide an example that creates the situation you’re in…

.ToProtoType()

Watch your inputs and list cycling (your desired list structure could be different than mine).

1 Like

Here is my situation as below.

import clr
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
from Revit.Elements import *

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

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

import System
from System.Collections.Generic import *
import sys

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

#walls = IN[0]
Mat = "Elevation Tag Face"
Faces = []
Geometry = []
output = []
gwall = []
gface = []
#for wall in walls:
#	Geo = wall.Geometry()
#	Geometry.append(Geo)
#	for f in Geo:
#		face = f.Faces
#		Faces.append(face)
		#Faces.append(wall)
#		Faces.GetEnumerator()

#Start scripting here:

walls = UnwrapElement(IN[0]) #Unwrap the wall in order to expose the API object

opt = Options() #Geometry options object. Needed when extracting geometry from a Revit element. 

wallsGeometry = []
wallFaces = []
output = [] #output list
for i in walls: #Iterate the walls
	elemId = i.Id #Get the element id, which we need to use as a parameter in the IsPainted method
	solids = i.get_Geometry(opt) #use the overloaded property get_Geometry to get the wall solids
	temp = [] #Temp container
	for j in solids: #Iterate the solids  
		faces = j.Faces #use the Faces property to get the faces
		for f in faces: #Iterate the faces
			temp.append(doc.IsPainted(elemId, f,)) #append the result to the temp container
			
	output.append(temp) #append the temp container to the out list
	gwall.append(i)
	gface.append(f)
		
# get wall by boolean
t2 = []
for sub_lst in output:
    t1 = []
    for item in sub_lst:
        if item:
            t1.append(gwall.pop(0))
        #else:
         #   t1.append(None)
    t2.append(t1)	
 
# get face by boolean
t3 = []
for sub_lst in output:
    t1 = []
    for item in sub_lst:
        if item:
            t1.append(gface.pop(0))
        #else:
         #   t1.append(None)
    t3.append(t1)	
# flattten list wall
newlist = []    
for sublist in t2:
	newlist.extend([i for i in sublist if 1 != 2])
	
# flatten list face
newfacelist = []    
for sublist in t3:
	newfacelist.extend([i for i in sublist if 1 != 2])

#get propreties
if isinstance(IN[0], list):walls = UnwrapElement(IN[0])
else: walls = [UnwrapElement(IN[0])]

#Get all wall IDS
elements = [UnwrapElement(i) for i in IN[0]]
IDS = List[Autodesk.Revit.DB.ElementId]()

for i in elements:
	IDS.Add(i.Id)
	
ElementIDs=[]

for i in elements:
	ElementIDs.append(i.Id)
	
# painted face off wall Get IDs
elements1 = [UnwrapElement(i) for i in (newlist)]
IDS1 = List[Autodesk.Revit.DB.ElementId]()

for i in elements1:
	IDS1.Add(i.Id)
	
ElementIDs1=[]

for i in elements1:
	ElementIDs1.append(i.Id)

#filter id & get wall
outlst = []
for w in ElementIDs:
	if w == ElementIDs1:
		outlst.append(True)
	else:
		outlst.append(False)
		
filter = []
output = []
for i in ElementIDs1:
	for ii in ElementIDs:
		if ii == i:
			filter.append(i)
	if list != []:
		output.append(filter)
		filter = []
		
		
	
	
OUT =  newlist, newfacelist,output,

Looks like the code sample I gave above will do what you’re after, though it isn’t clear to me what you’re after.

I want all face of wall with paint material and only walls having paint material.(Face, Wall)

If you had that before but only to the planar faces while you wanted Dynamo surfaces, add a line to iterate over your planar face’s (the last line of my code), at the end of the relevant loop, or add .ToProtoType() in the loop which fetched the planar faces.