Пример #1
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            var points = new List <Rhino.Geometry.Point3d>();

            if (!DA.GetDataList("Points", points))
            {
                return;
            }

            var tolerance = 0.0;

            if (!DA.GetData("Tolerance", ref tolerance))
            {
                return;
            }

            var boundingBox = true;

            if (!DA.GetData("BoundingBox", ref boundingBox))
            {
                return;
            }

            var strict = true;

            if (!DA.GetData("Strict", ref strict))
            {
                return;
            }

            var inverted = false;

            if (!DA.GetData("Inverted", ref inverted))
            {
                return;
            }

            var scaleFactor = 1.0 / Revit.ModelUnits;

            var targets = new List <Rhino.Geometry.Box>();

            Autodesk.Revit.DB.ElementFilter filter = null;

            if (boundingBox)
            {
                var pointsBBox = new Rhino.Geometry.BoundingBox(points);
                {
                    var box = new Rhino.Geometry.Box(pointsBBox);
                    box.Inflate(tolerance);
                    targets.Add(box);
                }

                pointsBBox = pointsBBox.ChangeUnits(scaleFactor);
                var outline = new Autodesk.Revit.DB.Outline(pointsBBox.Min.ToHost(), pointsBBox.Max.ToHost());

                if (strict)
                {
                    filter = new Autodesk.Revit.DB.BoundingBoxIsInsideFilter(outline, tolerance * scaleFactor, inverted);
                }
                else
                {
                    filter = new Autodesk.Revit.DB.BoundingBoxIntersectsFilter(outline, tolerance * scaleFactor, inverted);
                }
            }
            else
            {
                var filters = points.Select <Rhino.Geometry.Point3d, Autodesk.Revit.DB.ElementFilter>
                                  (x =>
                {
                    var pointsBBox = new Rhino.Geometry.BoundingBox(x, x);
                    {
                        var box = new Rhino.Geometry.Box(pointsBBox);
                        box.Inflate(tolerance);
                        targets.Add(box);
                    }

                    x = x.ChangeUnits(scaleFactor);

                    if (strict)
                    {
                        var outline = new Autodesk.Revit.DB.Outline(x.ToHost(), x.ToHost());
                        return(new Autodesk.Revit.DB.BoundingBoxIsInsideFilter(outline, tolerance * scaleFactor, inverted));
                    }
                    else
                    {
                        return(new Autodesk.Revit.DB.BoundingBoxContainsPointFilter(x.ToHost(), tolerance * scaleFactor, inverted));
                    }
                });

                var filterList = filters.ToArray();
                filter = filterList.Length == 1 ?
                         filterList[0] :
                         new Autodesk.Revit.DB.LogicalOrFilter(filterList);
            }

            DA.SetData("Filter", filter);
            DA.SetDataList("Target", targets);
        }
Пример #2
0
        public override Outline GetBoundingBox(View dBView)
        {
            var bbox = primitivesBoundingBox.ChangeUnits(1.0 / Revit.ModelUnits);

            return(new Outline(bbox.Min.ToHost(), bbox.Max.ToHost()));
        }