Get Element's LevelID through .LevelID or through Params

Get Element's LevelID through .LevelID or through Params

Anonymous
Not applicable
5,055 Views
5 Replies
Message 1 of 6

Get Element's LevelID through .LevelID or through Params

Anonymous
Not applicable

In a model that I'm analyzing I find many elements where their

element.LevelId

 is -1, but the 

element.LookupParameter("Level").AsElementId().IntegerValue

Has a valid level value.

 

What is the difference, and should I fall back from the first method to the second one if the value is -1?

0 Likes
5,056 Views
5 Replies
Replies (5)
Message 2 of 6

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @Anonymous,

 

Both are same and returns you the same value

Element.LevelId gives you Id of  your selected element Level.

Element.LookupParameter("Level").AsElementId().IntegerValue will search for the parameter "Level"and gets the elementid of the level and displays it as an integer value. 

 

 

 

 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 6

Anonymous
Not applicable

In the model I'm working on there are hundreds of elements where these 2 values are different.

element.LevelId is -1, and the second method returns a valid ID (not -1)

0 Likes
Message 4 of 6

draynorQNHWR
Participant
Participant

I ran into this today as well.  The elements in question were created via a 3rd party application. I was able to get the level id via a different route. 

Level lvl = doc.GetElement(pipe.ReferenceLevel.Id) as Level;

Hope that helps.

0 Likes
Message 5 of 6

grubdex
Enthusiast
Enthusiast

I'm having the exact same problem. I placed a standard Two Way Switch into my model.

Revit Lookup shows LevelId as -1, but the schedule level is set correctly in the element's Properties view, plus the correct level can be found in the family instance's Parameters for both the Schedule Level and the Level Parameter (checked via Revit Lookup). Does this have to do with the way the families are inserted? This makes any type of filtering via ElementLevelFilter extremely error-prone.

 

Edit: Here is a super simple example of what I mean. Note the light switch in Room 3.

 

0 Likes
Message 6 of 6

jeremy_tammik
Alumni
Alumni

Thank you for the sample model. I passed it on to the development team and asked them for an explanation.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open