Example #1
0
        /// <summary>
        /// Convert a Revit BoundingBox to a ProtoGeometry BoundingBox
        /// </summary>
        /// <returns></returns>
        public static Autodesk.DesignScript.Geometry.BoundingBox ToProtoType(this Autodesk.Revit.DB.BoundingBoxXYZ xyz)
        {
            xyz.Enabled = true;
            var corners = new[] { xyz.Min.ToPoint(), xyz.Max.ToPoint() };

            return(Autodesk.DesignScript.Geometry.BoundingBox.ByGeometry(corners));
        }
Example #2
0
        /// <summary>
        /// Get Base or SurveyPoint
        /// </summary>
        /// <param name="surveypoint"></param>
        /// <returns></returns>
        private static Point GetBaseOrSurveyPoint(bool surveypoint)
        {
            // Get Base or Survey point category
            RVT.BuiltInCategory category = (surveypoint)? RVT.BuiltInCategory.OST_SharedBasePoint : RVT.BuiltInCategory.OST_ProjectBasePoint;

            // Get Revit document
            RVT.Document doc = RevitServices.Persistence.DocumentManager.Instance.CurrentDBDocument;

            // Get all elements of the previously selected category
            Autodesk.Revit.DB.FilteredElementCollector collector = new RVT.FilteredElementCollector(doc).OfCategory(category);

            // Get the first element (should only be one)
            RVT.BasePoint element = (RVT.BasePoint)collector.ToElements().FirstOrDefault();

            if (element == null)
            {
                throw new Exception(Properties.Resources.CannotGetBaseOrSurveyPoint);
            }

            // Get the elements bounding box
            RVT.BoundingBoxXYZ box = element.get_BoundingBox(null);

            // Since the boundingbox is a point only, return Min or Max
            return(box.Max.ToPoint());
        }
Example #3
0
        /// <summary>
        /// Sets the near clipping plane distance of the view.  This is done by modifying the cropbox.  Please note that modifying the far clip distance will reset any near clip modifications.
        /// </summary>
        /// <param name="View">A Dynamo wrapped view</param>
        /// <param name="NearClipping">The Near Clipping Offset distance as a number from the camera</param>
        /// <returns name="View">Returns the modified view</returns>
        public static dynaView SetNearClippingDistance(dynaView3D View, double NearClipping)
        {
            string transactionName = "Set Near Clipping Distance";

            revitView rView = (revitView)View.InternalElement;

            revitBBxyz CropBox    = rView.CropBox;
            revitXYZ   oldMax     = CropBox.Max;
            revitXYZ   newMax     = new revitXYZ(oldMax.X, oldMax.Y, -Math.Abs(NearClipping));
            revitBBxyz NewCropBox = new revitBBxyz();

            NewCropBox.Max = newMax;
            NewCropBox.Min = CropBox.Min;

            revitDoc document = rView.Document;

            if (document.IsModifiable)
            {
                TransactionManager.Instance.EnsureInTransaction(document);
                rView.CropBox = NewCropBox;
                TransactionManager.Instance.TransactionTaskDone();
            }
            else
            {
                using (Autodesk.Revit.DB.Transaction trans = new Autodesk.Revit.DB.Transaction(document))
                {
                    trans.Start(transactionName);
                    rView.CropBox = NewCropBox;
                    trans.Commit();
                }
            }

            return(View);
        }
Example #4
0
        public static BoundingBox ToBoundingBox(this DB.BoundingBoxXYZ value, out Transform transform)
        {
            var rhino = RawDecoder.AsBoundingBox(value, out transform);

            UnitConverter.Scale(ref rhino, UnitConverter.ToRhinoUnits);
            UnitConverter.Scale(ref transform, UnitConverter.ToRhinoUnits);
            return(rhino);
        }
        public static Autodesk.DesignScript.Geometry.BoundingBox ToProtoType(this Autodesk.Revit.DB.BoundingBoxXYZ xyz, bool convertUnits = true)
        {
            xyz.Enabled = true;

            return(Autodesk.DesignScript.Geometry.BoundingBox.ByCornersCoordinateSystem(
                       xyz.Min.ToPoint(convertUnits), xyz.Max.ToPoint(convertUnits),
                       xyz.Transform.ToCoordinateSystem(convertUnits)));
        }
Example #6
0
        public static BoundingBox AsBoundingBox(DB.BoundingBoxXYZ bbox)
        {
            if (bbox?.Enabled ?? false)
            {
                var box = new BoundingBox(AsPoint3d(bbox.Min), AsPoint3d(bbox.Max));
                return(AsTransform(bbox.Transform).TransformBoundingBox(box));
            }

            return(BoundingBox.Unset);
        }
Example #7
0
        public static BoundingBox ToRhino(DB.BoundingBoxXYZ bbox)
        {
            if (bbox?.Enabled ?? false)
            {
                var box = new BoundingBox(ToRhino(bbox.Min), ToRhino(bbox.Max));
                return(ToRhino(bbox.Transform).TransformBoundingBox(box));
            }

            return(BoundingBox.Empty);
        }
Example #8
0
        public static BoundingBox ToRhino(this DB.BoundingBoxXYZ bbox)
        {
            if (bbox?.Enabled ?? false)
            {
                var box = new BoundingBox(bbox.Min.ToRhino(), bbox.Max.ToRhino());
                return(bbox.Transform.ToRhino().TransformBoundingBox(box));
            }

            return(BoundingBox.Empty);
        }
 private void InternalSetIsolation(Autodesk.Revit.DB.BoundingBoxXYZ bbox, bool isolate)
 {
     if (isolate && bbox != null)
     {
         InternalIsolateInView(bbox);
     }
     else
     {
         InternalRemoveIsolation();
     }
 }
Example #10
0
        public static BoundingBox AsBoundingBox(DB.BoundingBoxXYZ bbox, out Transform transform)
        {
            if (bbox?.Enabled ?? false)
            {
                var box = new BoundingBox(AsPoint3d(bbox.Min), AsPoint3d(bbox.Max));
                transform = AsTransform(bbox.Transform);
                return(box);
            }

            transform = Transform.Identity;
            return(BoundingBox.Unset);
        }
Example #11
0
 public static Box AsBox(DB.BoundingBoxXYZ bbox)
 {
     return(new Box
            (
                new Plane
                (
                    origin:    AsPoint3d(bbox.Transform.Origin),
                    xDirection: AsVector3d(bbox.Transform.BasisX),
                    yDirection: AsVector3d(bbox.Transform.BasisY)
                ),
                xSize: new Interval(bbox.Min.X, bbox.Max.X),
                ySize: new Interval(bbox.Min.Y, bbox.Max.Y),
                zSize: new Interval(bbox.Min.Z, bbox.Max.Z)
            ));
 }
Example #12
0
        /// <summary>
        /// Matches View3D's orientation and cropbox to an orthagonal view.  Also sets the View3D to isometric.
        /// </summary>
        /// <param name="View3D">The 3D view to change orientation and crop</param>
        /// <param name="SourceView">The source orthogonal view to acquire orientation and cropbox</param>
        /// <param name="Offset">Offset of the camera from the view direction of the source view</param>
        /// <returns name="View3D"></returns>
        public static DynaView3D View3dOrientToggleIsometric(DynaView3D View3D, DynaView SourceView, double Offset)
        {
            string transactionName = "View3dOrientToggleIsometric";

            RevitView3D rView       = (RevitView3D)View3D.InternalElement;
            RevitView   rSourceView = (RevitView)SourceView.InternalElement;

            RevitDoc document = rView.Document;

            // Cropbox
            RevitBB  cropbox = rSourceView.CropBox;
            RevitXYZ origin  = cropbox.Transform.Origin;

            // View Orientation
            RevitXYZ rEyePosition      = origin.Add(rSourceView.ViewDirection.Normalize().Multiply(Offset));
            RevitXYZ rUpDirection      = rSourceView.UpDirection;
            RevitXYZ rForwardDirection = rSourceView.ViewDirection.Negate();

            RevitViewOrientation viewOrient = new RevitViewOrientation(rEyePosition, rUpDirection, rForwardDirection);

            Action <RevitView3D, RevitViewOrientation, RevitBB> orientView = (view, orient, cropbb) =>
            {
                view.ToggleToIsometric();
                view.SetOrientation(orient);
                view.CropBox = cropbb;
            };

            if (document.IsModifiable)
            {
                TransactionManager.Instance.EnsureInTransaction(document);
                orientView(rView, viewOrient, cropbox);
                TransactionManager.Instance.TransactionTaskDone();
            }
            else
            {
                using (Autodesk.Revit.DB.Transaction trans = new Autodesk.Revit.DB.Transaction(document))
                {
                    trans.Start(transactionName);
                    orientView(rView, viewOrient, cropbox);
                    trans.Commit();
                }
            }
            return(View3D);
        }
Example #13
0
        public static Box ToBox(this DB.BoundingBoxXYZ value)
        {
            var rhino = RawDecoder.AsBoundingBox(value, out var transform);

            UnitConverter.Scale(ref rhino, UnitConverter.ToRhinoUnits);
            UnitConverter.Scale(ref transform, UnitConverter.ToRhinoUnits);

            return(new Box
                   (
                       new Plane
                       (
                           origin:    new Point3d(transform.M03, transform.M13, transform.M23),
                           xDirection: new Vector3d(transform.M00, transform.M10, transform.M20),
                           yDirection: new Vector3d(transform.M01, transform.M11, transform.M21)
                       ),
                       xSize: new Interval(rhino.Min.X, rhino.Max.X),
                       ySize: new Interval(rhino.Min.Y, rhino.Max.Y),
                       zSize: new Interval(rhino.Min.Z, rhino.Max.Z)
                   ));
        }
Example #14
0
        public Box BoxToSpeckle(DB.BoundingBoxXYZ box, string units = null)
        {
            // convert min and max pts to speckle first
            var min = PointToSpeckle(box.Min, units);
            var max = PointToSpeckle(box.Max, units);

            // get the base plane of the bounding box from the transform
            var transform = box.Transform;
            var plane     = DB.Plane.CreateByOriginAndBasis(transform.Origin, transform.BasisX.Normalize(), transform.BasisY.Normalize());

            var _box = new Box()
            {
                xSize     = new Interval(min.x, max.x),
                ySize     = new Interval(min.y, max.y),
                zSize     = new Interval(min.z, max.z),
                basePlane = PlaneToSpeckle(plane),
                units     = units ?? ModelUnits
            };

            return(_box);
        }
Example #15
0
        /// <summary>
        /// Set the far clipping distance of a view with far clipping active.  This method preserves the near clip distance, however setting the far clip distance using any other method will reset the near clip distance.
        /// </summary>
        /// <param name="View">A Dynamo wrapped view</param>
        /// <param name="FarClipping">The Far Clipping Offset distance as a number from the camera</param>
        /// <returns name="View">Returns the modified view</returns>
        public static dynaView SetFarClippingDistance(dynaView View, double FarClipping)
        {
            string transactionName = "Set Far Clipping Distance";

            revitView rView = (revitView)View.InternalElement;

            double NearClipping = rView.CropBox.Max.Z;

            revitDoc document = rView.Document;

            Action _SetFarClip = () =>
            {
                rView.get_Parameter(revitDB.BuiltInParameter.VIEWER_BOUND_OFFSET_FAR).Set(FarClipping);
                revitBBxyz CropBox    = rView.CropBox;
                revitXYZ   oldMax     = CropBox.Max;
                revitXYZ   newMax     = new revitXYZ(oldMax.X, oldMax.Y, -Math.Abs(NearClipping));
                revitBBxyz NewCropBox = new revitBBxyz();
                NewCropBox.Max = newMax;
                NewCropBox.Min = CropBox.Min;
                rView.CropBox  = NewCropBox;
            };

            if (document.IsModifiable)
            {
                TransactionManager.Instance.EnsureInTransaction(document);
                _SetFarClip();
                TransactionManager.Instance.TransactionTaskDone();
            }
            else
            {
                using (Autodesk.Revit.DB.Transaction trans = new Autodesk.Revit.DB.Transaction(document))
                {
                    trans.Start(transactionName);
                    _SetFarClip();
                    trans.Commit();
                }
            }

            return(View);
        }
Example #16
0
        public static View ViewSection(this Document document, Autodesk.Revit.DB.BoundingBoxXYZ boundingBoxXyz, string viewName = null, ElementId viewTemplateId = null, ViewDetailLevel viewDetailLevel = ViewDetailLevel.Coarse)
        {
            View result = null;

            ViewFamilyType vft = Query.ViewFamilyType(document, ViewFamily.Section);

            result = Autodesk.Revit.DB.ViewSection.CreateSection(document, vft.Id, boundingBoxXyz);

            Modify.SetViewDetailLevel(result, viewDetailLevel);

            if (viewTemplateId != null)
            {
                try
                {
                    result.ViewTemplateId = viewTemplateId;
                }
                catch (Exception)
                {
                    BH.Engine.Reflection.Compute.RecordWarning("Could not apply the View Template of Id " + viewTemplateId + "'." + ". Please check if it's a valid ElementId.");
                }
            }

            if (!string.IsNullOrEmpty(viewName))
            {
                try
                {
#if (REVIT2018 || REVIT2019)
                    result.ViewName = viewName;
#else
                    result.Name = viewName;
#endif
                }
                catch
                {
                    BH.Engine.Reflection.Compute.RecordWarning("There is already a view named '" + viewName + "'." + " It has been named '" + result.Name + "' instead.");
                }
            }

            return(result);
        }
Example #17
0
        /// <summary>
        /// Sets the cropbox of a view
        /// </summary>
        /// <param name="View">A Dynamo wrapped View</param>
        /// <param name="CropBox">A Revit BoundBoxXYZ</param>
        /// <returns name="View">A Dynamo wrapped View with an updated cropbox</returns>
        public static dynaView SetCropbox(dynaView View, revitBBxyz CropBox)
        {
            revitView rView    = (revitView)View.InternalElement;
            revitDoc  document = rView.Document;

            if (document.IsModifiable)
            {
                TransactionManager.Instance.EnsureInTransaction(document);
                rView.CropBox = CropBox;
                TransactionManager.Instance.TransactionTaskDone();
            }
            else
            {
                using (Autodesk.Revit.DB.Transaction trans = new Autodesk.Revit.DB.Transaction(document))
                {
                    trans.Start("Set CropBox of " + rView.Name);
                    rView.CropBox = CropBox;
                    trans.Commit();
                }
            }
            return(View);
        }
Example #18
0
        /// <summary>
        /// Return a grid of points in the space
        /// </summary>
        /// <param name="step">Lenght between two points</param>
        public List <Point> Grid(double step)
        {
            step = UnitConverter.DynamoToHostFactor(DB.UnitType.UT_Length) * step;
            List <Point> grid = new List <Point>();

            DB.BoundingBoxXYZ bb = InternalElement.get_BoundingBox(null);

            for (double x = bb.Min.X; x < bb.Max.X;)
            {
                for (double y = bb.Min.Y; y < bb.Max.Y;)
                {
                    DB.XYZ point = new DB.XYZ(x, y, bb.Min.Z);
                    if (InternalSpace.IsPointInSpace(point))
                    {
                        grid.Add(GeometryPrimitiveConverter.ToPoint(InternalTransform.OfPoint(point)));
                    }
                    y = y + step;
                }

                x = x + step;
            }

            return(grid);
        }
Example #19
0
        public void ToRevitBoundingBox_Method_PreservesValues()
        {
            var csOrigin = Point.ByCoordinates(1, 2, 3);
            var csX      = Vector.ByCoordinates(0, 1, 0);
            var csY      = Vector.ByCoordinates(0, 0, 1);

            var cs = CoordinateSystem.ByOriginVectors(csOrigin, csX, csY);

            var minPoint = Point.ByCoordinates(-2, -2, -2);
            var maxPoint = Point.ByCoordinates(2, 2, 2);

            Autodesk.Revit.DB.BoundingBoxXYZ boundingBoxXYZ = GeometryPrimitiveConverter.ToRevitBoundingBox(
                cs,
                minPoint,
                maxPoint);

            boundingBoxXYZ.Min.ShouldBeApproximately(minPoint.InHostUnits());
            boundingBoxXYZ.Max.ShouldBeApproximately(maxPoint.InHostUnits());

            boundingBoxXYZ.Transform.Origin.ShouldBeApproximately(csOrigin.InHostUnits());

            boundingBoxXYZ.Transform.BasisX.ShouldBeApproximately(csX);
            boundingBoxXYZ.Transform.BasisY.ShouldBeApproximately(csY);
        }
Example #20
0
 public cView(string sViewName, Autodesk.Revit.DB.View3D vView, BoundingBoxXYZ bXXY) //带参数的构造函数
 {
     this.sViewName = sViewName;
     this.vView     = vView;
     this.bXYZ      = bXYZ;
 }
 public static BoundingBox ToBoundingBox(this DB.BoundingBoxXYZ value)
 {
     var rhino = RawDecoder.ToRhino(value); UnitConverter.Scale(ref rhino, UnitConverter.ToRhinoUnits); return(rhino);
 }
Example #22
0
 public static BoundingBox ToRhino(this DB.BoundingBoxXYZ bbox) => RawDecoder.ToRhino(bbox);
Example #23
0
 /// <summary>
 /// GetMidpoint from bounding box
 /// </summary>
 /// <param name="box"></param>
 /// <returns></returns>
 private static Autodesk.Revit.DB.XYZ GetMidpoint(Autodesk.Revit.DB.BoundingBoxXYZ box)
 {
     return(box.Min + ((box.Max - box.Min) / 2));
 }