Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

how to search all AVF analysis result and remove them?

13 REPLIES 13
SOLVED
Reply
Message 1 of 14
zhuliyi0
1097 Views, 13 Replies

how to search all AVF analysis result and remove them?

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.

 
Labels (1)
13 REPLIES 13
Message 2 of 14
jeremy_tammik
in reply to: zhuliyi0

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
Message 3 of 14
zhuliyi0
in reply to: zhuliyi0

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.

Message 4 of 14
zhuliyi0
in reply to: jeremy_tammik

Just noticed I replied to myself. 

Message 5 of 14
jeremy_tammik
in reply to: zhuliyi0

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
Message 6 of 14
zhuliyi0
in reply to: jeremy_tammik

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.

Message 7 of 14
jeremy_tammik
in reply to: zhuliyi0

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
Message 8 of 14
aignatovich
in reply to: jeremy_tammik

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
in reply to: aignatovich

This is the solution! Thanks.

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

Message 10 of 14
jeremy_tammik
in reply to: zhuliyi0

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
Message 11 of 14
zhuliyi0
in reply to: jeremy_tammik

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.

Message 12 of 14
aignatovich
in reply to: zhuliyi0

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

 

 

Message 13 of 14
zhuliyi0
in reply to: aignatovich

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. 

Message 14 of 14
jeremy_tammik
in reply to: zhuliyi0

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Rail Community