Change Wall Level Constraints example

# -*- coding: utf-8 -*-
# Author: Erik Frits

from Autodesk.Revit.DB import *

# ╦  ╦╔═╗╦═╗╦╔═╗╔╗ ╦  ╔═╗╔═╗
# ╚╗╔╝╠═╣╠╦╝║╠═╣╠╩╗║  ║╣ ╚═╗
#  ╚╝ ╩ ╩╩╚═╩╩ ╩╚═╝╩═╝╚═╝╚═╝
#====================================================================================================
doc   = __revit__.ActiveUIDocument.Document
uidoc = __revit__.ActiveUIDocument
app   = __revit__.Application

# ╔╦╗╔═╗╦╔╗╔
# ║║║╠═╣║║║║
# ╩ ╩╩ ╩╩╝╚╝ MAIN
#====================================================================================================
# Get Levels
lvls = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Levels)\
                                       .WhereElementIsNotElementType().ToElements()

# Create Transaction to make changes in the project.
with Transaction(doc,__title__) as t:
    t.Start()

    # Get Wall
    wall = doc.GetElement(ElementId(346574))

    # Get Wall Parameters
    wall_base   = wall.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT)
    wall_top    = wall.get_Parameter(BuiltInParameter.WALL_HEIGHT_TYPE)
    wall_height = wall.get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM)

    # Choose New Levels
    new_base_level = lvls[2] # I am taking random level
    new_top_level  = lvls[3] # I am taking random level

    # Set New Associated Levels
    wall_base.Set(new_base_level.Id) # Set Base
    wall_top.Set(new_top_level.Id)   # Set Top

    # SET TOP: Unconnected Height
    wall_top.Set(ElementId(-1))      # Set Top: None
    wall_height.Set(20)              # Set Unconnected Height (20 feet)

    t.Commit()


# Author: Erik Frits

⌨️ Happy Coding!
Erik Frits