how to search all AVF analysis result and remove them?

how to search all AVF analysis result and remove them?

zhuliyi0
Enthusiast Enthusiast
2,360 Views
13 Replies
Message 1 of 14

how to search all AVF analysis result and remove them?

zhuliyi0
Enthusiast
Enthusiast

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.

 
0 Likes
Accepted solutions (1)
2,361 Views
13 Replies
Replies (13)
Message 2 of 14

jeremy_tammik
Alumni
Alumni

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!

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 14

zhuliyi0
Enthusiast
Enthusiast

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.

0 Likes
Message 4 of 14

zhuliyi0
Enthusiast
Enthusiast

Just noticed I replied to myself. 

0 Likes
Message 5 of 14

jeremy_tammik
Alumni
Alumni

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:

 

  • Impact on your application and/or your development.
  • The number of users affected.
  • The potential revenue impact to you.
  • The potential revenue impact to Autodesk.
  • Realistic timescale over which a fix would help you.
  • In the case of a request for a new feature or a feature enhancement, please also provide detailed Use cases for the workflows that this change would address.

 

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

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 6 of 14

zhuliyi0
Enthusiast
Enthusiast

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.

0 Likes
Message 7 of 14

jeremy_tammik
Alumni
Alumni

That is what I thought you meant.   🙂   Thank you for the confirmation.

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 8 of 14

aignatovich
Advisor
Advisor
Accepted solution

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

 

Message 9 of 14

zhuliyi0
Enthusiast
Enthusiast

This is the solution! Thanks.

I did a complete AVF clearing of all views in document.

0 Likes
Message 10 of 14

jeremy_tammik
Alumni
Alumni

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!

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 11 of 14

zhuliyi0
Enthusiast
Enthusiast

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.

0 Likes
Message 12 of 14

aignatovich
Advisor
Advisor

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();

 

 

0 Likes
Message 13 of 14

zhuliyi0
Enthusiast
Enthusiast

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. 

0 Likes
Message 14 of 14

jeremy_tammik
Alumni
Alumni

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...

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes