Remove view breaks

Remove view breaks

soheila.bigdeli
Enthusiast Enthusiast
536 Views
4 Replies
Message 1 of 5

Remove view breaks

soheila.bigdeli
Enthusiast
Enthusiast

Hi,

I want to use PathOFTravel feature in my addin, but view breaks exist that give the "A crop region is enabled in the view. The Path of Travel may not be the optimized route because it is calculating only inside the crop region. ... " error.

I used the following code to remove the view breaks, but it doesn't work.

Does anyone know how to temporarily remove the view breaks and use the PathOfTravel without this annoying warning?

I checked the UI, and it gives the same error, but when I check the route, to me it's good and seems to be the shortest and optimal path. So I was wondering if there is no straightforward solution for the above problem, adding a remove warning command. Any idea?

 

        public static void RemoveCropRegionsInAllViews(Document mydoc)
        {
            #region Code for making a list of levels on Floor plans

            List<View> Floorplans = new FilteredElementCollector(mydoc).OfClass(typeof(View)).WhereElementIsNotElementType().Cast<View>().Where(e => e.ViewType == ViewType.FloorPlan).ToList();
            List<ElementId> Levels = new List<ElementId>();
            List<View> FloorViews = new List<View>();

            try
            {
                foreach (Element e in Floorplans)
                {
                    if (e is View)
                    {
                        View floorview = e as View;
                        Level floorlevel;
                        if (floorview.GenLevel == null)
                        {
                            continue;
                        }
                        else
                        {
                            floorlevel = floorview.GenLevel;

                            bool check = false;
                            if (!Levels.Contains(floorlevel.Id))
                            {
                                Levels.Add(floorlevel.Id);
                                check = true;
                            }

                            if (!floorview.IsTemplate && check == true) //|| !Levels.Contains(floorlevel.Name))
                            {
                                FloorViews.Add(floorview);

                            }

                        }
                    }
                }

            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);

            }

            #endregion

            using (Transaction t = new Transaction(mydoc, "Remove the croped lines from the view"))
            {
                t.Start();
                foreach (var v in FloorViews)
                {
                    MessageBox.Show("Hi", v.Id.ToString());
                    ViewCropRegionShapeManager cropedView = v.GetCropRegionShapeManager();
                    cropedView.RemoveSplit();
                }
                t.Commit();
            }
        }

 

 

0 Likes
Accepted solutions (1)
537 Views
4 Replies
Replies (4)
Message 2 of 5

jeremy_tammik
Alumni
Alumni
Accepted solution

How about a completely different approach?

 

Use the Failure API to suppress the warning:

 

https://thebuildingcoder.typepad.com/blog/about-the-author.html#5.32

 

Maybe it can be achieved using the generic warning swallower listed in the topic group.

  

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

soheila.bigdeli
Enthusiast
Enthusiast
Thanks Jeremy, it worked.
However the running time has nearly doubled.
BTW, does it mean that there is no way in the API to remove the view breaks?
0 Likes
Message 4 of 5

jeremy_tammik
Alumni
Alumni

How has the running time doubled? Did you implement a failure processor, and that increased execution time? Would you like to show exactly how you implemented that? Maybe it can be improved.

 

No, it does not mean that the other approach is not possible. This alternative just seemed simpler to me, and more directly addressing the issue you described.

  

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

soheila.bigdeli
Enthusiast
Enthusiast

my fault, I just had to restart my laptop after constantly working for 4 days.
Now the running times are much better, way shorter than before when I needed to silence the warning manually.
But I used the following code:

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

            foreach (FailureMessageAccessor f in failures)
            {
                FailureSeverity fseverity = a.GetSeverity();
                if (fseverity == FailureSeverity.Warning) a.DeleteWarning(f);
                else
                {
                    a.ResolveFailure(f);
                    return FailureProcessingResult.ProceedWithCommit;
                }
            }
            return FailureProcessingResult.Continue;
        }

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

then I Call it as the following code:

 using (Transaction t = new Transaction(mydoc, "Check Distances"))
                    {
                        t.Start();
                        #region Remove warnings
                        WarningSwallower.setFailureDialogSuppressor(t);
                        #endregion
.
.
.
t.RollBack;
}

The only thing is that I assume that all warnings are suppressed. If there is a new warning in a new model, I would like to know.

So if there is a solution to remove the view breaks I think that would be the better solution. Do you have any idea or tip on how to implement this?

Thanks

0 Likes