Changing the level.Id and offset height of floors

Changing the level.Id and offset height of floors

mahshid.motie
Contributor Contributor
4,313 Views
11 Replies
Message 1 of 12

Changing the level.Id and offset height of floors

mahshid.motie
Contributor
Contributor

Hi all 🙂

 

I have revit file of a building with 5-6 floors but some of the floors doesnt have a right level associated with them. For example the floor element of 4th floor are linked to the 3rd level with a big offset height. I want to to have an organized revit file to export an organized IFC file. Therefor, I want to change the associated level (level.ID) and height offset of some of the floor elements. As level.Id is not a parameter to use get-set I have no idea how to it and didnt find any info online. Does anyone here have experience?

 

Thanks

0 Likes
Accepted solutions (2)
4,314 Views
11 Replies
Replies (11)
Message 2 of 12

FAIR59
Advisor
Advisor
Accepted solution

you can set the BuiltInParameter.LEVEL_PARAM and  BuiltInParameter.FLOOR_HEIGHTABOVELEVEL_PARAM

            Parameter p = floor.get_Parameter(BuiltInParameter.LEVEL_PARAM);
            Parameter p1 = floor.get_Parameter(BuiltInParameter.FLOOR_HEIGHTABOVELEVEL_PARAM);
            using (Transaction t = new Transaction(doc,"change floorlevel"))
            {
            	t.Start();
	            p.Set(level.Id); // set new level Id
	            p1.Set(2); // set new offset from level
	            t.Commit();
            }
0 Likes
Message 3 of 12

mahshid.motie
Contributor
Contributor

Hi 🙂

Thanks for the reply. Could you help me in another question? How can I print and check the value inside LEVEL_PARAM so I can decide which one to change and so on?

0 Likes
Message 4 of 12

mahshid.motie
Contributor
Contributor

I tried the code below and it only returns 0. I dont think that level_param is the same integer as level.id.

 

Parameter p = f.get_Parameter(BuiltInParameter.LEVEL_PARAM);
int a = p.AsInteger();
TaskDialog.Show("level_param", a.ToString());

0 Likes
Message 5 of 12

jeremytammik
Autodesk
Autodesk
Accepted solution

You need to use AsElementId to read an element id parameter value.

 

I tested and confirmed Fair59's solution.

 

Code:

 

      Floor floor
        = new FilteredElementCollector( doc )
          .WhereElementIsNotElementType()
          .OfCategory( BuiltInCategory.OST_Floors )
          .OfClass( typeof( Floor ) )
          .FirstElement() as Floor;

      FilteredElementCollector levels
        = new FilteredElementCollector( doc )
          .WhereElementIsNotElementType()
          .OfCategory( BuiltInCategory.OST_Levels )
          .OfClass( typeof( Level ) );

      int levelIdInt = floor.LevelId.IntegerValue;

      Level level = null;

      foreach( Level e in levels )
      {
        if( !e.Id.IntegerValue.Equals( levelIdInt ) )
        {
          level = e;
        }
      }

      if( null != level )
      {
        using( Transaction tx = new Transaction( doc ) )
        {
          tx.Start( "Set Floor Level" );

          Parameter p = floor.get_Parameter( BuiltInParameter.LEVEL_PARAM );
          Parameter p1 = floor.get_Parameter( BuiltInParameter.FLOOR_HEIGHTABOVELEVEL_PARAM );

          p.Set( level.Id ); // set new level Id
          p1.Set( 2 ); // set new offset from level

          tx.Commit();
        }
      }

  

Model before running add-in:

Model before running add-inModel before running add-in

Model after running add-in:

After running add-inAfter running add-in

 

Thank you for this explanation, Fair59!

  

Many elements' level cannot be set except in the constructor during creation.

  

Cheers,

  

Jeremy

  



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

Message 6 of 12

mahshid.motie
Contributor
Contributor

Hi Jeremy 🙂

 

Thanks for the answer and explanation. I tested the solution it works perfectly 🙂

0 Likes
Message 7 of 12

mahshid.motie
Contributor
Contributor

Dear Jeremy,

 

I also want to change the level.id of walls in my model and what is important for me is not to change the location of the walls (their start and end height). I want to set the base of the wall to a level with the ID: 1922170 and elevation of 7.69479m . And the top  of the wall to a level with the ID : 1922506 and elevation of 11.995m. I have tried the code below but it doesnt work and I have the error that says top of the wall is lower than the bottom. Could you please help me to find the mistake?

 

Parameter p = w.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT);
//ElementId id = p.AsElementId();
//TaskDialog.Show("kdjl", id.ToString());
Parameter p1 = w.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET);
Parameter p2 = w.get_Parameter(BuiltInParameter.WALL_HEIGHT_TYPE);
Parameter p3 = w.get_Parameter(BuiltInParameter.WALL_TOP_OFFSET);
int num1 = 1922170;
ElementId eleid1 = new ElementId(num1);

int num2 = 1922506;
ElementId eleid2 = new ElementId(num2);

double offset1 = UnitUtils.ConvertToInternalUnits(wMinZ - 7.69479, DisplayUnitType.DUT_METERS);
double offset2 = UnitUtils.ConvertToInternalUnits(11.995 - wMaxZ, DisplayUnitType.DUT_METERS);


p.Set(eleid1); // set new level Id
p1.Set(offset1); // set new offset from level

p2.Set(eleid2); // set new level Id
p3.Set(offset2); // set new offset from level

0 Likes
Message 8 of 12

jeremytammik
Autodesk
Autodesk

Make the walls unconnected before modifying anything (setting the top level to 'unconnected' represented by an invalid element id -1), and connect them to the proper level again after you have finished messing around with the levels.

 



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

0 Likes
Message 9 of 12

jeremytammik
Autodesk
Autodesk

Solution edited and shared for posterity by The Building Coder:

 

https://thebuildingcoder.typepad.com/blog/2019/04/set-floor-level-and-use-ipc-for-disentanglement.ht...

 

Cheers,

 

Jeremy

 



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

Message 10 of 12

mahshid.motie
Contributor
Contributor

Thanks for the reply 🙂

The top level is defined by WALL_HEIGHT_TYPE. Am I right?

0 Likes
Message 11 of 12

jeremytammik
Autodesk
Autodesk

Search for it:

 

https://duckduckgo.com/?q=WALL_HEIGHT_TYPE+revit

 

So, apparently, yes.

 



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

Message 12 of 12

emmanuel_maravillaKAVEM
Community Visitor
Community Visitor

hi. i badly need this tool. how do i run it sir. i attached here a site that has tons of floors that has a parameter called "height offset to level". it is currently set to 150. i need to set it to default, which is zero.

 

FYI, in the image, the opposite of what is currently selected needs to be changed from 150 to zero.

 

would appreciate all the help.

 

all the best

emmanuel_maravillaKAVEM_0-1690613124672.png

 

0 Likes