HELP: Get the Level ID of the element Beam (Structural Framing) with C#

HELP: Get the Level ID of the element Beam (Structural Framing) with C#

Anonymous
Not applicable
5,386 Views
13 Replies
Message 1 of 14

HELP: Get the Level ID of the element Beam (Structural Framing) with C#

Anonymous
Not applicable

Hi everyone:

 

I am trying to get the Level ID of the element Beam (Structural Framing).

 

The 'Revit Lookup' shows up -1 as a value. Where else can I find the Level ID of this element Beam?

 

get_level_id.png

 

Code:

 

foreach......

Level level = m_revit.ActiveUIDocument.Document.GetElement(fi.LevelId) as Level;
                                double elevation = level.Elevation;
                                string elevationName = level.Name;

 

Error:

 

get_level_id2.png

 

Thanks

 

David

0 Likes
5,387 Views
13 Replies
Replies (13)
Message 2 of 14

Revitalizer
Advisor
Advisor

Dear David,

 

if LevelId property is not set properly, you need to get Element's Level by one of the parameters.

 

Since this may differ from class to class, you may search for different BuiltInParameters.

 

Walls: WALL_BASE_CONSTRAINT

Roofs: ROOF_BASE_LEVEL_PARAM

Floors: LEVEL_PARAM

Stairs: STAIRS_BASE_LEVEL_PARAM

Rooms and Areas: ROOM_LEVEL_ID

FamilyInstances: FAMILY_LEVEL_PARAM

 

These parameters could also be set to null, and if a Family is workplane based, you could better use SCHEDULE_LEVEL_PARAM since this is its only Level relation (except you want to get the Level by geometric evaluation, which is not a good idea).

 

 

Best regards,

Reitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes
Message 3 of 14

Anonymous
Not applicable

Dear Reitalizer:

 

Thanks very much for respond.

 

Please can you give me an code example C# for get the Level ID of the element Beam (Structural Framing). I am using foreach for get the objects.

 

Thanks

 

Regards
David

0 Likes
Message 4 of 14

jeremytammik
Autodesk
Autodesk

Dear David,

 

Revitalizer explained to you how to proceed, and his explanation is clear.

 

You cannot realistically expect him or anyone else to write your final code for you, unless you are willing to pay them.

 

In that case, please contact Autodesk consulting for an estimate and a quote.

 

I hope this clarifies.

 

Best regards,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 5 of 14

Anonymous
Not applicable

Dear Jeremy:

 

Sorry, but three months ago I'm learning Revit API. I understand that you are over 15 years of experience, and for that reason, for you are clear explanation. I am developing an Add-in and only when there is like solving a specific issue request a code example to the forum. Normally aid means one or two specific lines of code. My intention is not to develop me all the Add-in. Furthermore, in the future I intend to share the knowledge learned in this community.

 

I apologize because I recently learning English.

 

Regards

 

David

0 Likes
Message 6 of 14

jeremytammik
Autodesk
Autodesk

Dear David,

 

I apologise too.

 

And, by the way, your English is perfectly fine. 

 

Basically, I would interpret Revitalizers advice as follows:

 

If the beam level id is undefined, i.e. -1, it is pretty complicated or maybe impossible to determine a sensible alternative.

 

So I would suggest giving up on that.

 

What you can sensibly do is determine the geometric location of the beam instance, and calculate between which levels it lies, even if those levels have not been assigned to it.

 

It really depends what you want this for.

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 7 of 14

Anonymous
Not applicable

Dear Jeremy:

 

Thank you very much for your understanding.

 

I'll take your advice and try to solve the problem with the geometric location.

 

Sorry but I can not understand why the ID of the beam level is -1. It is a configuration problem Revit?

 

Regards

 

David

0 Likes
Message 8 of 14

jeremytammik
Autodesk
Autodesk

Dear Frank,

 

The -1 means that the beam level id is not assigned.

 

This may be a user error by whoever built the model.

 

It may also be completely normal.

 

It depends mon the user intention, workflow, and best practices.

 

This is an issue to be discussed with your BIM manager.

 

It is not a configuration problem in Revit, just a normal usage error... or not an error at all, depending.

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 9 of 14

Revitalizer
Advisor
Advisor

Dear Jeremy, dear David,

sometimes level is reflected in LevelId, sometimes in a parameter.
Sometimes in none of them:

http://thebuildingcoder.typepad.com/blog/2011/01/family-instance-missing-level-property.html

I've seen many different cases so far.

In this case, what about about BuiltInParameter.INSTANCE_REFERENCE_LEVEL_PARAM, which reflects the "Reference Level" parameter visible in GUI properties ?


Best regards,
Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes
Message 10 of 14

Anonymous
Not applicable

Hi,

 

Just to add my two cents worth, I am working on something that involves beams and i am writing the level (name) to a schedule. What i have done is just get the reference level parameter of the beam.

 

foreach (Element e in new FilteredElementCollector(doc)
.OfClass(typeof(FamilyInstance))
.OfCategory(BuiltInCategory.OST_StructuralFraming))

Parameter mLevel = e.get_Parameter("Reference Level");
string level = pLevel.AsValueString();

 

Not sure if this helps in what you are trying to achieve with your add-in but thought i'd share. 

 

Regards,

 

Paul.

0 Likes
Message 11 of 14

Revitalizer
Advisor
Advisor

Hi poleary,

 

exactly, "Reference Level" is the equivalent to BuiltInParameter.INSTANCE_REFERENCE_LEVEL_PARAM.

Since parameter name can be language depending, it's better to use BuiltInParameter.

There are BuiltInParameter equvalents for each parameter except user defined ones, you can see it in its definition.

In my German Revit, same parameter is named "Referenzebene".

So just run your code in any non-English Revit to get an exception because parameter is null.

 

Nonetheless, thank you for your valid contribution!

 

Best regards,

Revitalizer

 

 

 

 

 




Rudolf Honke
Software Developer
Mensch und Maschine





Message 12 of 14

Anonymous
Not applicable

Thanks for the input Revitalizer. pretty new at this API stuff too 🙂

 

Much appreciated.

Message 13 of 14

Anonymous
Not applicable

Hello everyone:

 

I want first say thanks very much for you help.

 

I found the solution with the comment of the "poleary". I did some changes in the code for to find the Id of the beam:

 

//Get Level the element
Level level = m_revit.ActiveUIDocument.Document.GetElement(referenceLevel.AsElementId()) as Level;
                                double elevation = level.Elevation;
                                string elevationName = level.Name;

With this code, is obtained the id of the beam.

 

Best regards,

 

David

0 Likes
Message 14 of 14

hanseungjae
Explorer
Explorer

hi..

 

I have same problem.

 

I want to get level from beam.. but I did not.

 

Your solution is my hope.

 

I do not understand  (referenceLevel.AsElementId())..

 

Whree can I find it?

 

Best regards,

 

hans

0 Likes