Message 1 of 10
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Dear all,
I have this funny error I would like to track the visiblity changes in REVIT View. For this resons I subscribed to two events:
1. I subscribe to the ViewActivated event each time this event is called I create a new FilterdElementCollector.
2. In the Idling event I use this FilteredelementCollector to get all ElementIds;
This randomly produces System.StackOverflowExcpetion ... now I am a little lost in Debugging this issue, please help?
// getting the active view when changing the view will make things faster when checking visiblity
private void ViewActivated(object sender, ViewActivatedEventArgs e)
{
if (App.CurrentApp is null || App.CurrentApp.ActiveUIDocument is null) return;
Document doc = App.CurrentApp.ActiveUIDocument.Document;
this.ActiveViewElementCollector = new FilteredElementCollector(doc, doc.ActiveView.Id);
}
private bool VisiblityChanged()
{
if (ActiveViewElementCollector is null) return false;
// ICollection<ElementId> filter = new FilteredElementCollector(doc, doc.ActiveView.Id).ToElementIds();
ICollection<ElementId> filter = this.ActiveViewElementCollector.ToElementIds();
// einzige option hashset funktionen nutzen um event schneller zu machen...
HashSet<ElementId> visiblity = new HashSet<ElementId>(filter, new SortedElementId());
if (visiblity.Count != oldVisibility.Count || !oldVisibility.SetEquals(visiblity)) {
oldVisibility = visiblity;
return true;
}
return false;
}
Solved! Go to Solution.
Developer Advocacy and Support,