Getting a Revit property in Python throws a weird exception

Hi all,

I’m trying to get the CurveLoops property of a CurtainCell in python and it’s throwing a weird exception:

image

Anyone knows what’s going on here?
Here’s the code:

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
from RevitServices.Transactions import TransactionManager

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

doc = DocumentManager.Instance.CurrentDBDocument

wall = UnwrapElement(IN[0])
cells = wall.CurtainGrid.GetCurtainCells()
curveArrays = []

for cell in cells:
	curveArrays.append(cell.CurveLoops)

OUT = curveArrays

I think you’ll need to look at ICollection handling I. Python. Check this post and see if it gets you moving.

Thanks but I can already iterate through cells and get an Autodesk.Revit.Db.CurtainCell object.
Tried initialising an ICollection anyway and assigned the retrieved cells to that collection, then getting the property. Same exception is thrown:

cells = []
cellsCol = List[CurtainCell](cells)

curtainGrid = wall.CurtainGrid
cellsCol = curtainGrid.GetCurtainCells()

# and then
for cell in cellsCol:
	curves = cell.CurveLoops # throws the same error

Can you verify that the walls that you are inputing are curtain walls? Your code works fine for me in Revit 2019.2 / Dynamo 2.0.3.0.

I can generate similar errors when the inputed wall does not have a CurtainGrid. I can generate this exact error when the curtain grid contains grids that have segments removed from them.

I suggest wrapping your code in a try/except:

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
from RevitServices.Transactions import TransactionManager

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

doc = DocumentManager.Instance.CurrentDBDocument

wall = UnwrapElement(IN[0])
cells = wall.CurtainGrid.GetCurtainCells()
curveArrays = []
exceptions = []

try:
	for cell in cells:
		curveArrays.append(cell.CurveLoops)
except Exception, e:
	exceptions.append(str(e))

OUT = curveArrays, exceptions

This produces the following output:

3 Likes

Uh so glad to hear that. Was driving me crazy. I tested a few things and it seems that it throws this error when a segment of a grid line from the curtain wall has been removed.

Yes, that was my conclusion as well. Just wrap the code in a try/except and it is able to continue after it hits the exception.