supressing warning pop ups

supressing warning pop ups

NemKumar
Enthusiast Enthusiast
3,563 Views
1 Reply
Message 1 of 2

supressing warning pop ups

NemKumar
Enthusiast
Enthusiast

Hi All,

 

I am trying to display a cylinder triangulation by modelCurve(line).

When each model curve is created and rendered, I get very annoying

warning popups saying "line is slightly off the axis........".

 

Here is the code for calculating normal

 

public static SketchPlane createSketchPlane(Document inDoc, Curve inCurve)
{
      Plane plane;

      // Linear curves have no "normal" returned by compute derivatives
      if (inCurve is Line)
      { 
            XYZ point1 = inCurve.GetEndPoint(0);
            XYZ point2 = inCurve.GetEndPoint(1);
            XYZ tangent = (point2 - point1).Normalize();
            // Vertical line
            if (tangent.IsAlmostEqualTo(XYZ.BasisZ) || tangent.IsAlmostEqualTo(-XYZ.BasisZ))
            {
                   plane = inDoc.Application.Create.NewPlane(XYZ.BasisX, point1);
            }
            // Non-vertical line, use cross product with vertical to generate normal vector
            else
            { 
                   XYZ yVector = tangent.CrossProduct(XYZ.BasisZ).Normalize();
                   plane = inDoc.Application.Create.NewPlane(tangent, yVector, point1);
            }
       }
       // Non-linear curve supplies normal for sketch plane
       else
      {
             XYZ point = inCurve.Evaluate(0, true);
             Transform transform = inCurve.ComputeDerivatives(0, true);
             XYZ normal = transform.BasisZ;
             plane = inDoc.Application.Create.NewPlane(normal, point);
       }

       return inDoc.Create.NewSketchPlane(plane);
}

 

Also I tried to suppress warning by using this class

 

public class WarningSwallower : IFailuresPreprocessor
{
        public FailureProcessingResult PreprocessFailures(FailuresAccessor a)
        {
                // inside event handler, get all warnings

               IList<FailureMessageAccessor> failures = a.GetFailureMessages();

               foreach (FailureMessageAccessor f in failures)
               { 
                     FailureDefinitionId id = f.GetFailureDefinitionId();
                     if (BuiltInFailures.RoomFailures.RoomNotEnclosed == id)
                     a.DeleteWarning(f);
                }
                return FailureProcessingResult.Continue;
          }
}

 

and use this class as in 

 

public static void setFailureDialogSuppressor(Transaction tranasaction)
{
         FailureHandlingOptions failOpt = tranasaction.GetFailureHandlingOptions();
         failOpt.SetFailuresPreprocessor(new WarningSwallower());
         tranasaction.SetFailureHandlingOptions(failOpt);
}

 

and i make call it after

 

using (Transaction trans = new Transaction(mRevitDoc.Document))
{
       trans.Start("create Triangles");
       CFRevitGraphicsUtility.setFailureDialogSuppressor(trans);

       .....

       trans.Commit()

}

 

I need to fix this urgently as I dont have much time left.

I am not able to figure out what am I missing or doing wrong.

 

As I am creating 100s of cylinders, it popsup for 100s of times.

I dont know how to disable or suppress it.

OR fix the warning itself.

 

solution for either of the problem will be helpful.

 

Thanks in Advance.

0 Likes
Accepted solutions (1)
3,564 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable
Accepted solution

And what If you change your warning swallower to :

 

public FailureProcessingResult PreprocessFailures(FailuresAccessor a)
{
IList<FailureMessageAccessor> failures = a.GetFailureMessages();

foreach (FailureMessageAccessor f in failures)
{
FailureDefinitionId id = f.GetFailureDefinitionId();

FailureSeverity failureSeverity = a.GetSeverity();

if (failureSeverity == FailureSeverity.Warning)   //simply catch all warnings, so you don't have to find out what warning is causing the message to pop up
{
a.DeleteWarning(f);
}
else
{
return FailureProcessingResult.ProceedWithRollBack;
}
}
return FailureProcessingResult.Continue;
}