create views from new levels

# import pyrevit libraries
from Autodesk.Revit.DB import *

from pyrevit import script, revit, DB, forms
from System.Collections.Generic import List

doc = revit.doc

# get all levels, views, and view family types
levels_all = DB.FilteredElementCollector(doc).OfClass(DB.Level).WhereElementIsNotElementType().ToElements()
views_all = DB.FilteredElementCollector(doc).OfClass(DB.View).WhereElementIsNotElementType().ToElements()
vfts_all = DB.FilteredElementCollector(doc).OfClass(DB.ViewFamilyType).WhereElementIsElementType().ToElements()

# extract level names and IDs
level_data = []
for level in levels_all:

# extract view family types for floor plans
vft_data = []
for vft in vfts_all:
    if vft.ViewFamily == ViewFamily.FloorPlan:

# display a dialog to select levels
selected_levels =
    title="Select levels to create views",
    button_name="Create Views",

# display a dialog to select a view family type
selected_vft =
    title="Select a view family type",
    button_name="Create Views"

# create views based on the selected levels and view family types
t = Transaction(doc, 'Create Floor Plan Views')

for selected_level in selected_levels:
    level_id = selected_level
    level_name = selected_level

    for vft in vft_data:
        view_name = level_name
        view = DB.ViewPlan.Create(doc, selected_vft, selected_levels)
        view.Name = view_name


this script is it ok?

Hi @shuvro.arc , welcome to the community!

What are you asking here exactly?

Did you run the script in your pyrevit? does it throw any error, or behaves differently than what you thought?

From a quick look:

  • level_data can be directly created using ToElementIds instead of ToElements
  • pyRevit python library offers a Transaction object that handles the start and commit automatically using with Transaction():
  • you create the level_id, level_name, view_name to then assign the value to view.Name, you can directly to view.Name = selected_level
  • for the ViewPlan.Create method:
    • you always pass the same ViewFamilyType, but loop through all the vtf_data, so there will be many duplicates
    • you should use selected_vft.Id, not the object itself
    • you should use the selected_level.Id instead of selected_levels (the method accepts a single id, not a list of levels)
1 Like