2027 Method
Changes 0
M

Document.PostFailure

Description:
Posts a failure to be displayed to the user at the end of transaction.
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.
public FailureMessageKey PostFailure(
	FailureMessage failure
)
Return Value FailureMessageKey A unique key that identifies posted failure message in a document. If exactly the same error is posted more than once, and not removed between the postings, returned key will be the same every time.
// Execute function for an Updater triggered when new FamilyInstances are added
public void Execute(UpdaterData data)
{
   Document doc = data.GetDocument();
   Autodesk.Revit.ApplicationServices.Application app = doc.Application;
   foreach (ElementId id in data.GetModifiedElementIds())
   {
      AnalyticalMember fi = doc.GetElement(id) as AnalyticalMember;
      if (fi.StructuralRole == AnalyticalStructuralRole.StructuralRoleBeam)
      {
         if (fi.IsSingleCurve() == true)
         {
            Curve beamCurve = fi.GetCurve();
            // enforce beam length minimum of 12 inches
            if (beamCurve.Length < 12.0)
            {
               FailureMessage failMessage =
                     new FailureMessage(BuiltInFailures.CurveFailures.TooShort);
               failMessage.SetFailingElement(id);
               doc.PostFailure(failMessage);
            }
         }
      }
   }
}