Retrieve level from element

Retrieve level from element

MuirEng
Collaborator Collaborator
1,116 Views
5 Replies
Message 1 of 6

Retrieve level from element

MuirEng
Collaborator
Collaborator

confused by this one. 
I have elements in a model (mechanical devices). I can set up a schedule including "Level" and the level comes up fine.
In Dynamo I set up a script that gets (by category) all mechanical devices, and this feeds into GetParameterValueByName with "Level" as the input to the parameter name. This properly returns a list of levels. 

 

All good so far.

 

But in C# this code returns "Unknown" :

   Parameter levelParam = element.LookupParameter("Level");
   string levelName = levelParam != null ? levelParam.AsString() : "Unknown";

 

I've written some code to display all the parameters of the element along with the value and Level is listed, with the proper value. 

 

Why should this work so easily in Dynamo but not in C#?

Thanks for your advice. 

 

 

Brian Muir, P.Eng, Muir Engineering
0 Likes
1,117 Views
5 Replies
Replies (5)
Message 2 of 6

MuirEng
Collaborator
Collaborator

this also does not work

 

BuiltInParameter paraIndex = BuiltInParameter.LEVEL_PARAM;
Parameter levelParam = element.get_Parameter(paraIndex);
string levelName = levelParam != null ? levelParam.AsString() : "Unknown";

btw, is anyone else seeing constant pop ups asking for sign in? I'm logged in to my AutoDesk account. It's really annoying. Things freeze until I hit cancel. 

MuirEng_0-1728446791849.png

 

Brian Muir, P.Eng, Muir Engineering
0 Likes
Message 3 of 6

studio-a-int
Advocate
Advocate

If you try to get_Parameter(BuiltInParameter.SCHEDULE_LEVEL_PARAM).AsElementId() for those families, do still get a null?

0 Likes
Message 4 of 6

jeremy_tammik
Alumni
Alumni

What StorageType does LEVEL_PARAM have? Is it really a string? I would expect a level to be identified by its element id, not a string.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 5 of 6

TripleM-Dev.net
Advisor
Advisor

Hi @MuirEng ,

 

In Revit where the level "hides" is different between categories, even family types (facebased, levelbased etc) and between how elements are hosted (workplane a floor or level) and even between Revit versions.

 

The Dynamo node will propably have a extensive code behind it checking for the family placement type and some categories and using certain builtinparameters based on those (and more) conditions.

 

I've tried to built a global util that can read the level from any element but doesn't always come up with the correct Level if any.

Some parameters return a ElementId as host (which can be a level) but some only return a text value, with the prefix "Level : " (also depending revit version)

 

Use RevitLookup to inspect which parameters read out the level, specially if you are only concerned about one family category. If lucky the LevelId property of element will do it, else there are several parameters like:

- SCHEDULE_LEVEL_PARAM

- FAMILY_LEVEL_PARAM

- INSTANCE_FREE_HOST_PARAM

- HOST_ID_PARAM

- Etc...

 

- Michel

0 Likes
Message 6 of 6

GaryOrrMBI
Collaborator
Collaborator
I have a post asking about that same login pop-up posted on 10/2/2024...
It doesn't have any help or solution, just sayin...

-G
Gary J. Orr
GaryOrrMBI (MBI Companies 2014-Current)
aka (past user names):
Gary_J_Orr (GOMO Stuff 2008-2014);
OrrG (Forum Studio 2005-2008);
Gary J. Orr (LHB Inc 2002-2005);
Orr, Gary J. (Gossen Livingston 1997-2002)
0 Likes