Python Element.Geometry

How do I get geomentry of element in one python script node. I don’t quite understand what I am missing here.

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
floors = FilteredElementCollector(doc).OfClass(FilledRegion).ToElements()
out = []
for f in floors:
	out.append(f.Geometry())
OUT = out

maybe you can show us what is the working code? i mean you already got a working code, so whats wrong with it?

1 Like

I believe is because you need to convert the collected elements to Dynamo Type before calling its property “Geomtry” of that particular element

I need it to work on a single python node to be able to use the geometry and call a rollback transaction. The working code on this sample is just a separate of the one I pasted just without the Geometry() and as follows.
import clr
clr.AddReference(‘ProtoGeometry’)
from Autodesk.DesignScript.Geometry import *
elements = IN[0]
out =
for e in elements:
out.append(e.Geometry())
OUT = out

Then the error occurs because you are getting Autodesk.Revit.DB.Element (Revit element) instead of Revit.Elements.Element (dynamo element), and thus unable to use dynamo element property just like that. You can either use Revit.Elements.ElementSelector.ByElementId(YOURELEMENTID) or .ToDSType(False or True) method to get the element in dynamo. Then call the Geometry() method on dynamo element

Thanks it solved the issue. But then now I encountered a new problem which is I am unable to use either of the two element conversion inside a transaction.

do you mind eleborating more? im not able to see nor visualize what you just said

@stillgotme


import clr
clr.AddReference(“RevitServices”)
from System.Collections.Generic import List
clr.AddReference(“RevitNodes”)
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)
clr.AddReference(‘RevitAPI’)
from Autodesk.Revit.DB import *
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
def tolist(obj1):
if hasattr(obj1,“iter”): return obj1
else: return [obj1]
elem = UnwrapElement(tolist(IN[0]))
view = UnwrapElement(IN[1])
type = UnwrapElement(IN[2])
out =
t = Transaction(doc, “Create Fill Region”)
t.Start()
for e in elem:
ref = HostObjectUtils.GetTopFaces(e)[0]
face = doc.GetElement(ref).GetGeometryObjectFromReference(ref)
loop = face.GetEdgesAsCurveLoops()
fill = FilledRegion.Create(doc,type.Id,view.Id,loop)
out.append(fill.ToDSType(False).Geometry())
t.RollBack()
OUT = out

You will need to force close the dynamo’s automatic started transaction first, or use any api method to get on-going transaction and use it to generate a sub-transaction. With that being said, i think your script will still fail, but you can try

1 Like