The lag time is more likely in this portion where the script is iterating through all of your views and collecting the type of elements you’re after in each of those views:
for view in sheetviews:
viewColl = FilteredElementCollector(doc, view.Id).OfCategory(BuiltInCategory.OST_Viewers).ToElements()
Appending the view element to the list is just moving already collected data around, so appending booleans wouldn’t improve speed, but if you wanted the script to output booleans you’d modify the area of code you pasted like so:
if viewer.Name == vName:
refViews.append(True)
else:
refViews.append(False)
Fortunately with this script as it is, each consecutive run after the first one will be much quicker because all of the views and elements are already collected, but it sounds as if you might have been developing this to be a Dynamo Player script, so that doesn’t benefit you with speed.
I racked my brain on how to achieve what you’re after and can’t think of a method that would be 100% effective without requiring Dynamo to be searching through a collection of elements, so am unsure of a faster solution.
A possible direction to take would be to hide the referencing elements out of the incorrect views deductively… I’m not sure this would be the best method, but might be worth trying for your use case:
The Python script is giving you the element (call out, section, etc. ) that appears in the view that you dont wan’t as the referencing view, so the element that you’re looking to hide… this is the script:
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
views = []
if isinstance(IN[0],list):
for i in IN[0]:
views.append(UnwrapElement(i))
else:
views.append(UnwrapElement(IN[0]))
name = IN[1]
def getRefs(sheetviews, vName):
refViews = []
for view in sheetviews:
viewColl = FilteredElementCollector(doc, view.Id).OfCategory(BuiltInCategory.OST_Viewers).ToElements()
for viewer in viewColl:
if viewer.Name == vName:
refViews.append(viewer)
return refViews
OUT = getRefs(views, name)
Again, I don’t think this is the best method, as you would have to be hiding in view by each view until you see the correct referencing sheet / detail populating your parameters, which could probably get messy to keep track of.