Getting view ID of view from callout

@aaronnordstrom
my not so elegant solution is to test your callout selected name against the view list of names.

# -*- coding: utf-8 -*-
from pyrevit import revit, script, DB

doc = revit.doc
output = script.get_output()
output.close_others()

# get the selected callouts
callouts = revit.get_selection() # will give you the callout, not the cropped view itself
callouts_names = [c.Name for c in callouts]
# collect all views in the project
views = DB.FilteredElementCollector(doc).OfClass(DB.View).ToElements()
# filter the views to get only the callouts views
callout_views = []
for view in views:
    if view.Name in callouts_names:
        callout_views.append(view)

# get the first sheet in the project
sheet = DB.FilteredElementCollector(doc).OfClass(DB.ViewSheet).ToElements()[0] # get the first sheet in the project

count = 0
with revit.Transaction("Create Callouts from selection"):
    for callout_view in callout_views:
        try:
            vp = DB.Viewport.Create(doc, sheet.Id, callout_view.Id , DB.XYZ(count, 0, 0))
        except Exception as e:
            print(e)
        count += 1 # to offset the viewports
1 Like