The class is SpatialFieldManager , it cannot be find by filtered element collector, since AVF object exists only in RAM, not in model database. It will cause Revit to crash if the result is created inside a design option and that design option is duplicated. I would like to detect any result that's inside design option and warn the user, but can't find a way to search them.
Would be nice to fix the crash bug, or disallow analysis result to be placed inside design option altogether.
screenshot attached.
Solved! Go to Solution.
Solved by aignatovich. Go to Solution.
Can you produce a minimal reproducible case to demonstrate the crash that you describe for us to share with the Revit development team for analysis and possible enhancement?
https://thebuildingcoder.typepad.com/blog/about-the-author.html#1b
Thank you!
I cannot make a model since the object does not exist in model, only in RAM. The way to reproduce this is:
1, create design option set and some design options
2, get inside a design option (make it active)
3, use some tool to create AVF object. The API sample addin should do.
4, Exit to main model, duplicate the design option that contains AVF object. Revit will crash.
Dear Liyi Zhu,
Thank you for the steps to reproduce.
When you say, Revit crashes, what exactly do you mean?
I logged the issue REVIT-182024 [SpatialFieldManager within design option duplicated crashes] with our development team for this on your behalf as it requires further exploration and possibly a modification to our software. Please make a note of this number for future reference.
You are welcome to request an update on the status of this issue or to provide additional information on it at any time quoting this change request number.
This issue is important to me. What can I do to help?
This issue needs to be assessed by our engineering team and prioritised against all other outstanding change requests. Any information that you can provide to influence this assessment will help. Please provide the following where possible:
This information is extremely important. Our engineering team have limited resources, and so must focus their efforts on the highest impact items. We do understand that this will cause you delays and affect your development planning, and we appreciate your cooperation and patience.
Best regards,
Jeremy
By "Revit crashes", I mean Revit was busy for a while, then pops out the meesage box of "An unrecoverable error has occured" and asked for saving recovery file. Then the process exited, followed by the "send error message to Autodesk" dialog.
The recovered file does show correctly the copied design option.
That is what I thought you meant. 🙂 Thank you for the confirmation.
I haven't faced with crashes, because I haven't used it with design options yet. But I'll try to suggest a workaround:
1) collect open views via UIDocument.GetOpenUIViews method
2) for each opened view, try to get spatial field manager via SpatialFieldManager.GetSpatialFieldManager method, if it returns non-null, then spatial field manager exists
3) call SpatialFieldManager.Clear to remove AVF
This is the solution! Thanks.
I did a complete AVF clearing of all views in document.
Wow, congratulations on solving it and very many thanks to Alexander for the crucial idea.
Would you care to share the code to perform the cleaning, just for reference for others?
Thank you!
Sure, here is the code:
var views = new FilteredElementCollector(doc)
.WhereElementIsNotElementType()
.OfClass(typeof(View))
.Cast<View>()
.ToList();
foreach(var view in views)
{
var sfm = SpatialFieldManager.GetSpatialFieldManager(view);
if (sfm == null)
continue;
else
sfm.Clear();
}
Since there is no change to the model itself, no need to open a transaction.
I haven't tested your code, but I see some potential problems (they could or could not really occured).
The first is View itself, it could be a template, a schedule or other table views, it could be a view sheet or some "internal" views such as project browser. Not sure if GetSpatialManager would throw an exception in these cases now (remember, this behaviour could change in future Revit releases), but I would add a check, something like that:
...
.Cast<View>()
.Where(x => x.AllowsAnalysisDisplay()
...
The second thing, are you sure you have to check all views from the model? Maybe it will be enough to check opened views only?
var views = uidoc
.GetOpenUIViews()
.Select(x => doc.GetElement(x.ViewId))
.Cast<View>()
.Where(x => x.AllowsAnalysisDisplay())
.ToList();
Thanks for the check.
Yes I would add AllowAnalysisDisplay() too, if I knew it exist : P
I tried closing the view, then re-open it, the AVF object is still there, so I need to do a document-wide search, not just opened views.
Many thanks to Zhu Liyi for raising this and to Alexander for the good solution!
Preserved for posterity on the blog:
https://thebuildingcoder.typepad.com/blog/2021/09/kfpopeye-open-source-avf-and-other-cleanup.html#3
Also pointed out this workaround to the development team, who are pondering how to fix it internally for the future...
Can't find what you're looking for? Ask the community or share your knowledge.