GetElement(ElementId) gives out 'None Type'

When i get an element from the boundary segment and apply any method from the Elements class to it i get the error:

AttributeError: ‘NoneType’

Why is this happening?

import sys,os
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('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')
from Autodesk.Revit import DB
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB import FilteredElementCollector as Filter
clr.AddReference('System')
from System.Collections.Generic import List

from Autodesk.Revit.DB import Structure
from Autodesk.Revit.DB import JoinType

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
uidoc = uiapp.ActiveUIDocument




options = SpatialElementBoundaryOptions()
rooms = Filter(doc).OfCategory(DB.BuiltInCategory.OST_Rooms).WhereElementIsNotElementType().ToElements()

for room in rooms:
			
	for segment in room.GetBoundarySegments(options):
	
		for crv in segment:
		
			el = doc.GetElement(crv.ElementId)
			
			elType = el.GetTypeId()

It has to be FilteredElementCollector

@Deniz_Maral this is the FilteredElementCollector , take a closer look

Ok, now I see it. The Curve class has no attribute named ElementId…
What is your goal?

@Deniz_Maral el in my code produces Wall. If I print el.GetElementId() then everything works fine. I just want to access an element from room boundary segments

@zergg52 is this what you are after? el.WallType

Yes, I tried it but they give out the same.

Can you append/ output the el element?, the error reports NoneType…
It worked fine for me as you can see in the screenshot

Oh, I didn’t take into account that this wall edge gives ElementId -1

that’s why the error occurs

Thanks to all!

Why don’t you use Room.Boundaries from Clockwork?

1 Like