How to create a Warning

How to create a Warning

Kevin.Bell
Advisor Advisor
5,288 Views
17 Replies
Message 1 of 18

How to create a Warning

Kevin.Bell
Advisor
Advisor

Hi,

 

I've a routine which moves elements around, but in some occasions it comes across a an element that can't be moved.

 

I can get the routine to filter them out so its not an issue, but I'd like to create a Warning message for the user.

 

I can do this with the TaskDialog class, but really I'd like to create a non critical Warning message, which warns the user, but does not stop them working - the same sort of warning you get if you delete a room from the model:

 

Capture.JPG

I can't see a way of creating this in the API - can it be done?

 

Thanks.

 

 

0 Likes
Accepted solutions (2)
5,289 Views
17 Replies
Replies (17)
Message 2 of 18

jeremytammik
Autodesk
Autodesk

The Revit API provides the TaskDialog class for this and nothing else.

 

It has rather a large number of options.

 

Maybe some of them satisfy your need.

 

Check out the Revit UI API labs in 2_Revit_UI_API:

 

https://github.com/jeremytammik/AdnRevitApiLabsXtra

 

Cheers,

 

Jeremy

 

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 18

Kevin.Bell
Advisor
Advisor

Ok, thanks - I use task dialog, but I was hoping for something that didn't stop the user and force them to hit OK.

 

Cheers.

0 Likes
Message 4 of 18

jeremytammik
Autodesk
Autodesk

Oh, I see.

 

Yes, for that you can use a modeless Windows form and close it automatically after a specified time period. 

 

No problem; here is a description for AutoCAD that (exdeptionally) applies to Revit as well (since it has nothing to do with either of them, really):

 

https://drive-cad-with-code.blogspot.com/2014/02/showing-and-closing-modeless-formdialog.html

  

Please let us know how you end up using this.

 

Maybe it will be useful for others as well.

 

Thank you!

 

Cheers,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 5 of 18

FAIR59
Advisor
Advisor
Accepted solution

you can define your own failure, and let Revit display it.

 

first you create a FailureDefinitionId and FailureDefinition,

// Create failure definition Ids
Guid guid1 = new Guid("d0cf2412-08fe-476b-a6e6-e9a98583c52c");
FailureDefinitionId  m_idWarning = new FailureDefinitionId(guid1);

// Create failure definitions and add resolutions
FailureDefinition m_fdWarning = FailureDefinition.CreateFailureDefinition(m_idWarning, FailureSeverity.Warning, "Textvalue is changed for all instances in textchain");

m_fdWarning.SetDefaultResolutionType(FailureResolutionType.SetValue);

then you can display the warning,

 

 

 FailureMessage fm = new FailureMessage(ExternalApplication.m_idWarning);
 doc.PostFailure(fm);
0 Likes
Message 6 of 18

jeremytammik
Autodesk
Autodesk

Cool. Thank you! Is that modeless?

 

These steps are also demonstrated in the Revit SDK sample files SDK/Samples/ErrorHandling/CS/Command.cs and 

SDK/Samples/PerformanceAdviserControl/CS/FlippedDoorCheck.cs.

 

 

Cheers,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 7 of 18

FAIR59
Advisor
Advisor

@jeremytammik wrote:

Cool. Thank you! Is that modeless?

 

Yes, this is a Revit warning as depicted in the Original question. You can totally ignore it, and keep working.

The one caveat I can think of: it will probably be displayed when the control reverts back to Revit. (not sure)

 

Frank 


 

0 Likes
Message 8 of 18

jeremytammik
Autodesk
Autodesk
Accepted solution

Thank you very much for the invaluable help, Frank!

 

Published here for posterity:

 

http://thebuildingcoder.typepad.com/blog/2018/06/creating-a-warning-using-the-failure-api.html

 

Cheers,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 9 of 18

Kevin.Bell
Advisor
Advisor

Perfect, thanks, I'll give that a try.

0 Likes
Message 10 of 18

PTHN-NNDuc
Explorer
Explorer

Seems like it's locked in Revit 2020

PTHNPTThanh_0-1624355179600.png

 

0 Likes
Message 11 of 18

Sean_Page
Collaborator
Collaborator

I know this is a little older, but would you have any guidance on how (if possible) to get the Warning to stick to the document? I am able to display the warning, set the resolution and all that, but as stated in the Docs, it is NOT stored in the document. 

For this request, I am working inside an IUpdater and would like to throw the warning (working) AND keep in the Warnings list if that is possible.

Sean Page, AIA, NCARB, LEED AP
Partner, Computational Designer, Architect
0 Likes
Message 12 of 18

jeremy_tammik
Alumni
Alumni

Sorry, dunno off-hand. I asked the development team for you.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 13 of 18

ricaun
Advisor
Advisor

I believed that the PostFailure stored the FailureMessage in the document, but looks like it does not.

 

In the documentation explain: https://www.revitapidocs.com/2017/7184ff0a-f30e-03fb-904f-fb557df6fa37.htm

Remarks: If code inside transaction detects a problem that needs to be communicated to the user, it should report these conditions via this method. Failures will be validated and possibly resolved at the end of transaction. Warnings posted via this method will not be stored in the document after they are resolved. A unique key returned by postFailure can be stored for the lifetime of transaction and used to remove failure message if it is no longer relevant.

 

Warnings look not as useful as I thought. 😐

 

 

 

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

Message 14 of 18

Sean_Page
Collaborator
Collaborator

I am assuming it is related to the FailureAccessor approach with the same method, but I was wanting to see if it was possible to "store" a warning before I headed down that path.

 

https://www.revitapidocs.com/2017/5d25d459-a1b0-eef4-4766-b00bd1f5ba79.htm

Sean Page, AIA, NCARB, LEED AP
Partner, Computational Designer, Architect
0 Likes
Message 15 of 18

jeremy_tammik
Alumni
Alumni

Yes, apparently ricaun is right; the development team replies:

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 16 of 18

Sean_Page
Collaborator
Collaborator

Thanks @jeremy_tammik , I was unfortunately prepared for that answer, just wanted to make sure I hadn't missed something. As always, I appreciate your time!

Sean Page, AIA, NCARB, LEED AP
Partner, Computational Designer, Architect
0 Likes
Message 17 of 18

Sean_Page
Collaborator
Collaborator

Maybe I am the only one, but seems like this would be nice to have.

 

https://forums.autodesk.com/t5/revit-ideas/post-custom-warnings-to-the-warnings-list-inside-the-docu...

Sean Page, AIA, NCARB, LEED AP
Partner, Computational Designer, Architect
Message 18 of 18

schnierer.gabor
Advocate
Advocate

For me it took quite a while to figure out how to display the modeless yellow pop-up called miniwarning.

Because although the original question asks for a modeless dialog, the solution provides a modal one.

The key is the ForcedModalHandling flag in FailureHandlingOptions is by default true. You have to manually set it to false.

 

options.SetForcedModalHandling(false);

 

Here is the context

using (Transaction t = new Transaction(doc, "Post failure"))
{
    var options = t.GetFailureHandlingOptions();
    var preproccessor = new FailurePreproccessor();
    options.SetFailuresPreprocessor(preproccessor);
    options.SetForcedModalHandling(false);
    t.SetFailureHandlingOptions(options);

    t.Start();
    FailureMessage fm = new FailureMessage(failureDefinitionId);
    doc.PostFailure(fm);
    t.Commit();
}

 

0 Likes