how do i use BoundingBoxIntersectsFilter to find floors intersecting with stair BoundingBox

how do i use BoundingBoxIntersectsFilter to find floors intersecting with stair BoundingBox

pnoZFP35
Explorer Explorer
529 Views
1 Reply
Message 1 of 2

how do i use BoundingBoxIntersectsFilter to find floors intersecting with stair BoundingBox

pnoZFP35
Explorer
Explorer

I'm trying to find the floors my stairs is going to and from

 help1.PNG

 

I am using BoundingBoxIntersectsFilter to find the floors that are intersecting with my stairs BoundingBox. when I then find the floors I want to take the one with the highest Z value, and save it to "Upper slab ref". And the one with the lowest Z value and save it to "Lower slab ref".

 

And now to the problem when I try to do this I will get to many floors or non at all

how can I make it so it will always find the right floors, in any given situation.

 

The middle stair will get 4 floors

help2.PNG

 

The highest stair will get 2 floors but non of them is from the upper floor. and the lowest stair will find non at all.

help3.PNG

 

code is shown below 

 

ICollection<Element> AllStairs = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Stairs).WhereElementIsNotElementType().ToElements();
                FilteredElementCollector collectorSlab = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Floors).WhereElementIsNotElementType();
                
                foreach (Element el in AllStairs)
                {
                    IDictionary<string, double> StairsSlab = new Dictionary<string, double>();
                    List<string> allSlabs = new List<string>();
                    BoundingBoxXYZ bb = el.get_BoundingBox(doc.ActiveView);

                    Outline outline = new Outline(bb.Min, bb.Max);
                    BoundingBoxIntersectsFilter bbfilter = new BoundingBoxIntersectsFilter(outline);
                    collectorSlab.WherePasses(bbfilter).ToElements();

                    if (collectorSlab != null)
                    {
                       foreach (Element e in collectorSlab)
                        {
                            BoundingBoxXYZ location = e.get_BoundingBox(doc.ActiveView);
                            double zPoint = location.Max.Z;
                            allSlabs.Add(e.Id.ToString());



                            StairsSlab.Add(e.Id.ToString(), zPoint);
                        }
                    }

                    if (StairsSlab[allSlabs[0]] > StairsSlab[allSlabs[1]])
                    {
                        tr.Start("Reload");
                        el.LookupParameter("Upper slab ref").Set(allSlabs[0].ToString());
                        el.LookupParameter("Lower slab ref").Set(allSlabs[1].ToString());
                        tr.Commit();
                    }
                    else
                    {
                        tr.Start("Reload");
                        el.LookupParameter("Upper slab ref").Set(allSlabs[1].ToString());
                        el.LookupParameter("Lower slab ref").Set(allSlabs[0].ToString());
                        tr.Commit();
                    }
                }

 

 

0 Likes
530 Views
1 Reply
Reply (1)
Message 2 of 2

jeremy_tammik
Alumni
Alumni

Are you just trying to determine the top and bottom floors reached by the multi-storey stairs? If so, I can imagine there is an easier way to do so than what you describe. For instance, is it not possible to determine the stairs' maximum and minimum vertical Z extents? Then you can easily eliminate all the floors in between those two values, and determine which of the two left over is the upper and lower one.

  

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