Calling Element.Faces in Python

Hey All,

I need to integrate the Element.Faces node into Python… I am getting an error, ‘type’ object has no attribute faces…

familyFaces = []
for hosted in itemlist:
   fcs = Element.Faces(itemlist)
   familyFaces.append(fcs)

I believe the problem is that I need to define the Element.Faces method as coming from:
from Autodesk.DesignScript.Geometry import *

Like this…

familyFaces = []
for hosted in itemlist:
   fcs = Autodesk.DesignScript.Geometry.Element.Faces(itemlist)
   familyFaces.append(fcs)

But then I get the error message ‘Autodesk’ not defined…

Would anyone be able to help?

Thanks,

Mark

sorry but wouldn’t this be:

familyFaces = []
for hosted in itemlist:
   fcs = Element.Faces(hosted)
   familyFaces.append(fcs)

otherwise there would be no need for the for loop in the first place :slight_smile:

@Jonathan.Olesen well yes ok you’re right :blush:

Please forgive my poorly debugged code… Dyslexia and coding don’t sit well together…

But the problem still remains :stuck_out_tongue:

I think this post will help you :slight_smile:

Thanks for the suggestion, unfortunately I get 'Family Instance Has No Attribute…

I get results from this method… But when I extract faces later, I get no references to work with down the line…

familySolid = []
for hosted in itemlist:
   solid = hosted.Geometry()
   familySolid.append(solid)

Here’s the dyn&rvt… Dim Walls-C.dyn (32.4 KB) dim.rvt (1.9 MB)

I am interested to know how to call these nodes, I can bring in some but not others… there’s a discussion here, but not the final working code…

Thanks again :slight_smile:

Mark

Hi @Mark.Ackerley sorry for the late reply, had some other business to attend to :slight_smile:

I think this might be what you are looking for:

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

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

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

clr.AddReference('DSCoreNodes')
import DSCore
from DSCore import *

elem = IN[0]
output = []
faces = []

elemgeo = elem.Geometry()
for i in elemgeo:
	faces.append(i.Faces)

for i in faces:
	for x in i:
		Surfgeo = x.SurfaceGeometry()
		output.append(Surfgeo)
OUT = output

image

2 Likes

Hi @Jonathan.Olesen,

Thanks for your efforts, unfortunately it’s not working :frowning:
image

Thanks again,

Mark

Edit:

Some other ways that aren’t doing it…!

#surfacesForRef = []
#for i in faceSrf:
#    ref = i.Tags.LookupTag("RevitFaceReference")
#    output.append(ref)

#edgeRefs = []
#for srfedges in faceSrf:
#    srfEdgesRefs = srfedges.Edges
#    for refs in srfEdgesRefs:
#		output.append(refs.Reference)

faceRefs = []
for facerefs in faces:
    for fcrefs in facerefs:
	    output.append(fcrefs.Reference)

The last one gives ‘Face object has no attribute Reference’…!

I didn’t know that you still wished a multi-directional reference between the geometry in Revit and Dynamo.

The method “SurfaceGeometry” simply creates a dynamo copy of the faces geometry, see here:
http://www.revitapidocs.com/2018.1/c8d124ed-1e6e-d08c-3e4b-b37c4bc2890b.htm

I have no idea how you’d convert the geometry to a dynamo surface while maintaining the Revit tags… :confused:

(Also NodeToCode crashes my Dynamo when attempted on “Element.Faces” xD)

Hey,

Sorry I wasn’t clear :frowning: that’s why I wanted to call the node/method Element.Faces… it seems to be doing this in a magical way…

I believe zero touch nodes should be able to be called from Python? I can do it with other ones, just that one doesn’t obey my call!

Node to Code just gives me x.Faces which obviously confuses Python, because there are other methods with the same name.

So I need to define this method as being from a particular library, Design Script…

Autodesk.DesignScript.Geometry.Element.Faces(itemlist)

But then I get the fail that name Autodesk isn’t recognised…

That’s what I was trying to say in my original post…

Cheers,

Mark.

Edit. I call the Design Script Library at the top of my code…

from Autodesk.DesignScript.Geometry import *

Isn’t there to call the Revit API or someting ?

I think that it is not possible to call custom nodes in Python.

Hi @mellouze

I don’t think it is a custom node…

image

Cheers,

Mark

Try this:

x=[]
for i in IN[0].Faces:
	x.append(i)
OUT = x

1 Like

Boom! Thanks :smiley:

Apologies for making that so difficult!

Mark

No problem! I was kinda surprised that it was that “easy” :stuck_out_tongue:

1 Like