Find Referring Views

Find Referring Views

timothylogan2019
Participant Participant
909 Views
1 Reply
Message 1 of 2

Find Referring Views

timothylogan2019
Participant
Participant

Is there an API equivelant to the 'Find Referring Views' option when you right-click on a view through the API?  I seem to remember doing it once years ago, but I could be misremembering.  Nothing that I saw in the SDK help file or with Revit Lookup seemed to point to a way to do it.  I see the view parameter Referencing Sheet and Referencing Detail, but nothing that's pointed to the list of all views that say a section appears on.

 

Thanks,

-Tim

0 Likes
910 Views
1 Reply
Reply (1)
Message 2 of 2

timothylogan2019
Participant
Participant

Not sure if it's a good answer, but I did find a way to do it.  Basically find the element that corresponds to a given view, and then iterating through views that are on sheets and checking agaisnt them.  The slowdown occurs when iterating through the views and looking for the element (section mark, callout, elvation marker,...)  The FilteredElementCollector with the view override can be really slow when it has to open a lot of views and look through them.  The benefit is that once you've done it once, doing it again for another view is actually pretty fast.  So first time takes minutes, beyond that it takes seconds.

 

 

public void ReferenceViews()
{
	Document doc = this.ActiveUIDocument.Document;
	View view = doc.ActiveView;

	FilteredElementCollector viewersCollector = new FilteredElementCollector(doc);
	viewersCollector.OfCategory(BuiltInCategory.OST_Viewers);
			
	Element elem = null;
	foreach(Element e in viewersCollector)
	{
		if(e.Name == view.Name)
			elem = e;
	}
	
	if(elem != null)
	{
		DateTime start = DateTime.Now;
		FilterableValueProvider provider = new ParameterValueProvider(new ElementId(BuiltInParameter.VIEWPORT_SHEET_NUMBER));
		FilterRule rule = new FilterStringRule(provider, new FilterStringGreater(), string.Empty, false);
		ElementParameterFilter epf = new ElementParameterFilter(rule, false);
		FilteredElementCollector viewCol = new FilteredElementCollector(doc).WherePasses(epf);
		viewCol.OfClass(typeof(View));
		
		StringBuilder sb = new StringBuilder();
		foreach(View v in viewCol)
		{
			if(v.Id.IntegerValue == view.Id.IntegerValue || v.IsTemplate || v.ViewType == ViewType.DrawingSheet || v.ViewType == ViewType.ColumnSchedule)
				continue;
			try
			{
				ICollection<ElementId> col = new FilteredElementCollector(doc, v.Id).ToElementIds();
				if(col.Contains(elem.Id))
					sb.AppendLine("View: " + v.Name);
			}
			catch{}
		}
		TaskDialog.Show("Test", "Time Elapsed: " + (DateTime.Now - start).ToString() + "\n" + sb.ToString());
	}
}