
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm creating a list of views that contain .dwg ImportInstance(s). For each view in the document, I'm using a FilteredElementCollector to get a list of elements meeting the criteria; if the list of elements meeting the criteria is not empty, then the view is added to the list:
foreach (Element viewElement in viewElements) { View view = (View)viewElement;
var stopwatch = new Stopwatch(); stopwatch.Start(); List<Element> elementsInView = new FilteredElementCollector(doc, view.Id).OfClass(typeof(ImportInstance)).Where(e => e.Category.Name.EndsWith(".dwg")).OfType<Element>().ToList(); stopwatch.Stop(); Debug.WriteLine(view.Name + ": " + stopwatch.ElapsedMilliseconds + "ms"); if(elementsInView.Count > 0) //if the current view contains at least 1 DWG ImportInstance, then the view is added to the list { viewsWithCAD.Add(view); continue; } }
The FilteredElementCollector can understandably take an upwards of 4000ms to collect elements from a view containing many elements. My goal is only to see if a single element exists in a view--not to collect all of the elements meeting the criteria; if I could make the FilteredElementCollector stop immediately after finding an element meeting the criteria, that would be helpful.
I would appreciate any advice on how to achieve this more efficiently.
Thank you.
Solved! Go to Solution.