Hello!
Small question: I want to have this function:
elevation = 1000
lvl = Level.GetNearestLevelId(doc, elevation)
How do I call this function as it is a member of Level
, but I need to specify this level first. The fact that this function is a member of Level
is quite odd, as it feels it should be a member of document
and return the Level.
How does one get the level closest to a certain elevation?
Cheers! Rick
Hi @Rickkrrd,
Your code snippet should work.
In Level.GetNearestLevelId
, Level is the Autodesk.Revit.DB.Level class not a specific level element.
For information, the Nearest Level node already exists in the Genius Loci package.
1 Like
Hi @Alban_de_Chasteigner,
Yes I thought so as well, but I’m keep getting:
AttributeError: ‘type’ object has no attribute ‘GetNearestLevelId’
This happens also with your Nearest Level function. And it also gives an error:
NameError: name ‘SpecTypeId’ is not defined
Seems to me like something goes wrong in importing libraries… But I’m using RevitAPI much more and that works fine Any thougths on what is going wrong?
I need to use the RevitAPI as I’m developing add-ins. Never really had a problem like this before
Did you see that this method is only available in Revit 2022 ?
For previous Revit versions, this doesn’t exist.
2 Likes
Ah shoot yes I saw that
So this is the source code of the Nearest Level node, without the SpecTypId. Still getting the AttributeError: ‘type’ object has no attribute ‘GetNearestLevelId’
error.
import clr
# Import RevitAPI Classes
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
numbers = IN[0] if isinstance(IN[0],list) else [IN[0]]
result=[]
for number in numbers:
result.append(doc.GetElement(Autodesk.Revit.DB.Level.GetNearestLevelId(doc,number)))
if isinstance(IN[0], list): OUT = result
else: OUT = result[0]
seems to me this should just work fine. DB is properly working, as I can use it in other functions.
Ah shoot.
GetNearestLevelId is a R2022 feature as well.