Quantcast
Channel: All Revit API Forum posts
Viewing all articles
Browse latest Browse all 66683

Re: Find Views in which an element is visible (by geometry or actual visibility)

$
0
0

Hi Jeremy,

actually Im not using the quick filter. I tried to, but the boundingbox of the views need altering because the Z values are not correct (for viewplans atleast). Im prefiltering alot with quick filters, but when it comes to the actual boundingbox comparision I've expanded the views into memory. You can see this in the code in the bottom.

 

Anyway, I've perfected my boundingbox filter into something that works for me. I tried to get it to work in viewsections, but that was just too big of an obstacle for me today, the client didnt need that in the end, so I just skipped that part. The problem was figuring out the boundingbox since the coordinatesystem shifts in viewsections.
I tried to look a the transform of the boundingbox, and shift it accordingly, but it didnt work.

 

Maybe you can shine some light on whats wrong or how to accomplish it, Jeremy?

 

The performance of the boundingbox version is extreme in comparison, using a stopwatch I measured the following times:

~22 seks for the traditional way and 125 ms for the boundingbox way.

 

Anyway, here is the extensionmethod I use now:

Snippet

public static bool IntersectsBoundingBox(this View view, BoundingBoxXYZ targetBoundingBox)
{        var viewBoundingBox = view.CropBox;    if (!view.CropBoxActive)    {        using (Transaction tr = new Transaction(view.Document, "Temp"))        {            //If the cropbox is not active we cant extract the boundingbox (we rollback so we dont change anything and also increase performance)            tr.Start();            view.CropBoxActive = true;            viewBoundingBox = view.CropBox;            tr.RollBack();        }    }        Outline viewOutline = null;    if (view is ViewPlan)    {        var viewRange = (view as ViewPlan).GetViewRange();        //We need to change the boundingbox Z-values because they are not correct (for some reason).         var bottomXYZ = (view.Document.GetElement(viewRange.GetLevelId(PlanViewPlane.BottomClipPlane)) as Level).Elevation + viewRange.GetOffset(PlanViewPlane.BottomClipPlane);        var topXYZ = (view.Document.GetElement(viewRange.GetLevelId(PlanViewPlane.CutPlane)) as Level).Elevation + viewRange.GetOffset(PlanViewPlane.CutPlane);        viewOutline = new Outline(new XYZ(viewBoundingBox.Min.X, viewBoundingBox.Min.Y, bottomXYZ), new XYZ(viewBoundingBox.Max.X, viewBoundingBox.Max.Y, topXYZ));    }        if(!viewBoundingBox.Transform.BasisY.IsAlmostEqualTo(XYZ.BasisY)) //this is where I try to hand viewsections. But I cant get it to work!!    {        viewOutline = new Outline(new XYZ(viewBoundingBox.Min.X, viewBoundingBox.Min.Z, viewBoundingBox.Min.Y ), new XYZ(viewBoundingBox.Max.X, viewBoundingBox.Max.Z, viewBoundingBox.Max.Y ));    }    using (var boundingBoxAsOutline = new Outline(targetBoundingBox.Min, targetBoundingBox.Max))    {        return boundingBoxAsOutline.Intersects(viewOutline, 0);    }
}

 I hope someone finds it useful and good luck Abba!

 

/Erik


Viewing all articles
Browse latest Browse all 66683

Trending Articles