Create View: LegendView

We can't create legends with Revit API!

However we can duplicate existing and it will do the same! Don't forget Transaction

# -*- coding: utf-8 -*-
#⬇ IMPORTS
from Autodesk.Revit.DB import *
from pyrevit.forms import alert

#📦 VARIABLES
doc         = __revit__.ActiveUIDocument.Document
all_views   = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Views).ToElements()
all_legends = [view for view in all_views if view.ViewType == ViewType.Legend]

#✅ Check Legend in the Project
if not all_legends:
    alert("There has to be at least 1 Legend View in the project! "
          "Please create one and try again.", exitscript=True)

#👉 GET RANDOM LEGEND
random_legend = all_legends[0]

#🆕 CREATE NEW LEGEND VIEW
new_legend_view_id    = random_legend.Duplicate(ViewDuplicateOption.Duplicate)
new_legend_view       = doc.GetElement(new_legend_view_id)

#🔎 Change Scale
new_legend_view.Scale = 100

⌨️ Happy Coding!
Erik Frits