1

I have read this article that explains how to set the level of a floor without moving it. The article refers to the Building Coder where the BuiltInParameter.LEVEL_PARAM is used. However this method no longer works due to updates in the API. I am able to find the new ForgeTypeId of the parameter, but I am told that the LevelId is a Read-Only parameter when I try to run my code. How do I change the level of a floor? In the GUI it's easy, how can this be so hard in the API and so easy in the GUI?

Doing this in RevitPythonShell, my code is the following:

typeid = s0.LookupParameter("Level").GetTypeId()
floorid = ElementId(5873761)
with Transaction(revit.doc,"change level") as t:
    p = s0.GetParameter(typeid)
    t.Start()
    p.Set(floorid)
    t.Commit()

Grateful for any help!

  • Hey there, could you clarify what `s0` is in your example? The steps would be to fetch the 'Level' parameter of your floor, and set it to the ID of the Level you have fetched – Callum Sep 30 '22 at 04:15
  • 1
    Please check whether the parameter `p` in your code is read-only. If it is, you may have to create a new floor to change the level and transfer the original floor properties to it. Many Revit elements' level can only be set during creation: https://thebuildingcoder.typepad.com/blog/2020/06/creating-material-texture-and-retaining-pixels.html#4 – Jeremy Tammik Sep 30 '22 at 05:57
  • @Callum: Sorry, s0 is the PythonRevitShell variable for the first element in the current selection, in this case a floor. I have tried that approach as well with the same result. – Hauk-Morten Sep 30 '22 at 11:32
  • @JeremyTammik: Ok, best option is to create a new one then. Very Revit-like to be unable to change things. Thank you! – Hauk-Morten Sep 30 '22 at 11:35

1 Answers1

1

You shouldnt have to make a new floor - you can change the level of a floor just like any other Parameter:

levels = list(FilteredElementCollector(doc).OfClass(Level))

newLevelName = 'Level 2'
newLevel = [i for i in levels if i.Name == newLevelName][0]

floor = s0 # your selected floor here
levelParam = floor.LookupParameter('Level')

t = Transaction(doc, 'Changing Floor Level to '+newLevelName)
t.Start()
try:
    levelParam.Set(newLevel.Id)
    print 'changed level of floor to',level.Name
except Exception as e:
    print '!!!',e
t.Commit()

Interestingly, the UserModifiable value of the levelParam is False - turns out users can still modify it though!

Callum
  • 578
  • 3
  • 8
  • 1
    Thank you, I will try this! Sorry for late response, I haven't been at StackOverflow for a while, been doing other work. – Hauk-Morten Aug 11 '23 at 08:09