Get the reference callout on views

Hi,

I’m going through an exercise to review all the reference callout on a lot of sheets, so I’m trying to generate a list of reference callout on views. However I can only find the ‘real’ callouts, is there an API that I miss that I can get reference ones.

Thanks,

J

Have a look at ReferenceableViewUtils
a bit of AI + some love:

# encoding: utf-8
from pyrevit import DB, HOST_APP, script

output = script.get_output()

doc = HOST_APP.doc

def viewports_on_sheet(sheet):
    return [doc.GetElement(vpid) for vpid in sheet.GetAllViewports()]

def placed_view(vp):
    return doc.GetElement(vp.ViewId)

def referenced_view_id(ref_elem_id):
    return DB.ReferenceableViewUtils.GetReferencedViewId(doc, ref_elem_id)

data = []
for sheet in DB.FilteredElementCollector(doc).OfClass(DB.ViewSheet):
    for vp in viewports_on_sheet(sheet):
        parent_view = placed_view(vp)
        for rid in parent_view.GetReferenceCallouts():          # << key call
            ref_view = doc.GetElement(referenced_view_id(rid))
            # find if referenced view is placed, and on which sheet/detail number
            vp_of_ref = list(DB.FilteredElementCollector(doc).OfClass(DB.Viewport).ToElements())
            host_vps = [x for x in vp_of_ref if x.ViewId == ref_view.Id]
            if host_vps:
                host_vp = host_vps[0]
                host_sheet = doc.GetElement(host_vp.SheetId)
                detail_no = host_vp.get_Parameter(DB.BuiltInParameter.VIEWPORT_DETAIL_NUMBER).AsString()
                sheet_num = host_sheet.SheetNumber
            else:
                detail_no = ""
                sheet_num = "(unplaced)"
            data.append([sheet.SheetNumber, sheet.Name, parent_view.Name, ref_view.Name, sheet_num, detail_no])

output.print_table(data, columns=["Sheet Number", "Sheet Name", "Parent View Name", "Ref View Name", "Ref View Sheet", "Ref View Detail No"])

Sorry for the late reply, this is exactly what I’m looking for, cheers.

2 Likes