简体   繁体   中英

How do I change the level of a floor through the API?

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!

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM