Get Face Reference using Python

I am trying to get to the Reference object of a PlanarFace, using Python.

Underneath you can see the API object that I’m looking for: (a screenshot from RevitLookup addin):

I have gotten to the PlanarFaces using following code

doc = DocumentManager.Instance.CurrentDBDocument
element = UnwrapElement(IN[0])
options = Autodesk.Revit.DB.Options()

#get element geometry
geometryInstance = element.get_Geometry(options)

#get instance geometry
inst_geom = []
for i in geometryInstance:
inst_geom.append(i.GetInstanceGeometry())

#iterate to remove empty geometry objects
filtered = []
for i in inst_geom[0]:
if list((i.Faces)).Count != 0:
filtered.append(i)

#get faces of filtered geometry
faces = []
for i in filtered:
faces.append(i.Faces)

OUT = faces

image

This is where the problem starts.
From here I have tried 2 methods to get to the Reference object. Both fail.

Method 1: use face.Reference

#get face reference object
face_refs = []
for face in faces[0]:
face_refs.append(face.Reference)

OUT = face_refs

I get Nulls:

image

Method 2: use face.Tags.LookupTag(“RevitFaceReference”)

I did this once in another workflow:

So I tried it also here, but failed.
It says PlanarFace has no attribute ‘Tags’

Can someone help me get there?

Maybe try Revit Api’s Reference Array? Seems to work for me like that:

refArray = ReferenceArray()

refArray.Append(f.Reference)

Thanks for the suggestion. But I’m afraid I dont know how to use your method.

I just typed in exactly what you said, and Python doesnt get it (so do I :stuck_out_tongue:

Could it be that I am missing a reference maybe? Im currently using these:

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

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

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

clr.AddReference("RevitAPI")
import Autodesk
clr.AddReference("System")
from System.Collections.Generic import *

If think it’s in:

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

Allright. At least adding reference from Autodesk.Revit.DB import * helped resolving the error ‘ReferenceArray is not defined’. Thanks for that.

I still get nulls though…

How did you do it? Any other thoughts?

Got it.

“To get the reference of a face that is part of a solid, you need to set Option.ComputeReferences = true.”

Thanks to https://forums.autodesk.com/t5/revit-api-forum/how-to-get-the-face-reference/td-p/3949069

8 Likes

Tell me, did you manage to get reference from PlanarFace?