예제 #1
0
        /// <summary>
        /// This node will obtain the outline of the Viewport title if one is used. This is the label outline.
        /// </summary>
        /// <param name="viewport">Viewport to obtain data from.</param>
        /// <returns name="labelOutline">The label outline of the viewport.</returns>
        /// <search>
        /// viewport, Viewport.LabelOutline, rhythm
        /// </search>
        public static List <Autodesk.DesignScript.Geometry.Curve> LabelOutline(global::Revit.Elements.Element viewport)
        {
            Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument;
            //obtain the element id from the sheet
            Autodesk.Revit.DB.Viewport internalViewport = (Autodesk.Revit.DB.Viewport)viewport.InternalElement;

            //this obtains the label outline
            var labelOutline = internalViewport.GetLabelOutline();
            //create plane that corresponds to sheet plane
            Plane labelPlane   = Plane.ByOriginNormal(labelOutline.MaximumPoint.ToPoint(), Vector.ZAxis());
            var   labelCuboid  = Cuboid.ByCorners(labelOutline.MaximumPoint.ToPoint(), labelOutline.MinimumPoint.ToPoint());
            var   labelSurface = labelCuboid.Intersect(labelPlane);
            List <Autodesk.DesignScript.Geometry.Curve[]> labelCurves = new List <Autodesk.DesignScript.Geometry.Curve[]>();

            foreach (Surface surf in labelSurface)
            {
                labelCurves.Add(surf.PerimeterCurves());
            }
            List <Autodesk.DesignScript.Geometry.Curve> labelSheetCurves = new List <Autodesk.DesignScript.Geometry.Curve>();

            //pull the curves onto a plane at 0,0,0
            foreach (Autodesk.DesignScript.Geometry.Curve[] curve in labelCurves)
            {
                foreach (Autodesk.DesignScript.Geometry.Curve c in curve)
                {
                    labelSheetCurves.Add(c.PullOntoPlane(Plane.XY()));
                }
            }

            return(labelSheetCurves);
        }
예제 #2
0
 /// <summary>
 /// Create a Viewport from a user selected Element.
 /// </summary>
 /// <param name="viewport"></param>
 /// <param name="isRevitOwned"></param>
 /// <returns></returns>
 internal static Viewport FromExisting(Autodesk.Revit.DB.Viewport viewport, bool isRevitOwned)
 {
     return(new Viewport(viewport)
     {
         IsRevitOwned = isRevitOwned
     });
 }
예제 #3
0
        private bool updatePositionsInit(Autodesk.Revit.DB.ViewSheet curViewSheet)
        {
            Autodesk.Revit.DB.XYZ       norXYZ          = null;
            Autodesk.Revit.DB.ElementId deltaViewportId = null;

            if (curViewSheet != null)
            {
                ICollection <ElementId> curViewportsIdsCollection = curViewSheet.GetAllViewports();
                foreach (ElementId curViewportId in curViewportsIdsCollection)
                {
                    if (this.selViewportsIdsAndPositions.ContainsKey(curViewportId))
                    {
                        Autodesk.Revit.DB.Viewport curViewport = doc.GetElement(curViewportId) as Autodesk.Revit.DB.Viewport;
                        if (curViewport != null)
                        {
                            norXYZ = curViewport.GetBoxCenter();

                            break;
                        }
                    }
                }
            }

            List <ElementId> viewportIds            = new List <ElementId>(this.selViewportsIdsAndPositions.Keys);
            PageAlignmentToolRequestHandler handler = new PageAlignmentToolRequestHandler(norXYZ, deltaViewportId, viewportIds);
            ExternalEvent exEvent = ExternalEvent.Create(handler);

            exEvent.Raise();

            return(true);
        }
예제 #4
0
        private void geSelectedtViewportsIdsAndPositions()
        {
            this.selViewportsIdsAndPositions.Clear();

            FilteredElementCollector docFilter = new FilteredElementCollector(doc).OfClass(typeof(Autodesk.Revit.DB.Viewport));

            if (docFilter != null)
            {
                FilteredElementIterator docFilterIterator = docFilter.GetElementIterator();
                while (docFilterIterator.MoveNext())
                {
                    Autodesk.Revit.DB.Viewport curViewport = docFilterIterator.Current as Autodesk.Revit.DB.Viewport;
                    if (curViewport != null)
                    {
                        ElementId curViewId = curViewport.ViewId;
                        if (curViewId != null)
                        {
                            Autodesk.Revit.DB.View curView = doc.GetElement(curViewId) as Autodesk.Revit.DB.View;
                            if (curView != null)
                            {
                                if (curView.Scale == this.selectedScale)
                                {
                                    XYZ curXYZ = curViewport.GetBoxCenter();
                                    this.selViewportsIdsAndPositions.Add(curViewport.Id, curXYZ);
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #5
0
        /// <summary>
        /// Given a list of viewport element IDs, the function will get the viewport from the document and give each viewport a temporary sheet number.  Function will ignore legends.
        /// </summary>
        /// <param name="viewPortIds">Revit ElementId of the viewports.</param>
        /// <param name="doc">The Revit Document the viewports are in.</param>
        /// <returns name="viewports">Returns the Revit viewports.</returns>
        internal static List <revitViewport> _tempRenumberViewports(List <revitElemId> viewPortIds, revitDoc doc)
        {
            List <revitViewport> viewPorts = new List <revitViewport>();
            int i = 1;

            foreach (revitElemId id in viewPortIds)
            {
                revitViewport vp = (revitViewport)doc.GetElement(id);
                revitView     v  = (revitView)doc.GetElement(vp.ViewId);

                if (
                    v.ViewType == revitDB.ViewType.FloorPlan ||
                    v.ViewType == revitDB.ViewType.CeilingPlan ||
                    v.ViewType == revitDB.ViewType.Elevation ||
                    v.ViewType == revitDB.ViewType.ThreeD ||
                    v.ViewType == revitDB.ViewType.DraftingView ||
                    v.ViewType == revitDB.ViewType.AreaPlan ||
                    v.ViewType == revitDB.ViewType.Section ||
                    v.ViewType == revitDB.ViewType.Detail ||
                    v.ViewType == revitDB.ViewType.Rendering
                    )
                {
                    viewPorts.Add(vp);

                    revitDB.Parameter param = vp.get_Parameter(revitDB.BuiltInParameter.VIEWPORT_DETAIL_NUMBER);
                    if (param != null)
                    {
                        param.Set("!!" + i);
                    }
                    i++;
                }
            }
            return(viewPorts);
        }
예제 #6
0
 /// <summary>
 /// This node will set the viewport's box center given the point.
 /// </summary>
 /// <param name="viewport">The viewport to set.</param>
 /// <param name="point">The point to use.</param>
 /// <search>
 /// viewport
 /// </search>
 public static void SetBoxCenter(global::Revit.Elements.Element viewport, Point point)
 {
     Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument;
     Autodesk.Revit.DB.Viewport internalViewport = (Autodesk.Revit.DB.Viewport)viewport.InternalElement;
     TransactionManager.Instance.EnsureInTransaction(doc);
     internalViewport.SetBoxCenter(point.ToRevitType());
     TransactionManager.Instance.TransactionTaskDone();
 }
예제 #7
0
        /// <summary>
        /// This node will obtain the view from the given viewport.
        /// </summary>
        /// <param name="viewport">Viewport to obtain view from.</param>
        /// <returns name="view">The view that belongs to the viewport.</returns>
        /// <search>
        /// viewport, location,rhythm
        /// </search>
        public static global::Revit.Elements.Element GetView(global::Revit.Elements.Element viewport)
        {
            Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument;
            Autodesk.Revit.DB.Viewport internalViewport = (Autodesk.Revit.DB.Viewport)viewport.InternalElement;
            ElementId viewId = internalViewport.ViewId;

            global::Revit.Elements.Element view = doc.GetElement(viewId).ToDSType(true);

            return(view);
        }
예제 #8
0
        public static Dictionary <string, object> LocationData(global::Revit.Elements.Element viewport)
        {
            //obtain the element id from the sheet
            Autodesk.Revit.DB.Viewport internalViewport = (Autodesk.Revit.DB.Viewport)viewport.InternalElement;
            //obtain the box center of the viewport
            var boxCenterInternal = internalViewport.GetBoxCenter().ToPoint();

            //Construct new point at sheet elevation of 0
            Autodesk.DesignScript.Geometry.Point boxCenter =
                Autodesk.DesignScript.Geometry.Point.ByCoordinates(boxCenterInternal.X, boxCenterInternal.Y, 0);
            //this obtains the box outline
            var boxOutline = internalViewport.GetBoxOutline();
            //temporary geometry
            var bBox      = BoundingBox.ByCorners(boxOutline.MaximumPoint.ToPoint(), boxOutline.MinimumPoint.ToPoint());
            var boxCuboid = Cuboid.ByCorners(boxOutline.MaximumPoint.ToPoint(), boxOutline.MinimumPoint.ToPoint());
            //create plane that corresponds to sheet plane
            Plane boxPlane   = Plane.ByOriginNormal(boxOutline.MaximumPoint.ToPoint(), Vector.ZAxis());
            var   boxSurface = boxCuboid.Intersect(boxPlane);
            List <Autodesk.DesignScript.Geometry.Curve[]> boxCurves = new List <Autodesk.DesignScript.Geometry.Curve[]>();

            foreach (var geometry in boxSurface)
            {
                var surf = (Surface)geometry;
                boxCurves.Add(surf.PerimeterCurves());
                surf.Dispose();
            }
            List <Autodesk.DesignScript.Geometry.Curve> boxSheetCurves = new List <Autodesk.DesignScript.Geometry.Curve>();

            //pull the curves onto a plane at 0,0,0
            foreach (Autodesk.DesignScript.Geometry.Curve[] curve in boxCurves)
            {
                foreach (Autodesk.DesignScript.Geometry.Curve c in curve)
                {
                    boxSheetCurves.Add(c.PullOntoPlane(Plane.XY()));
                    c.Dispose();
                }
            }

            //dispose of temporary geometries
            boxCuboid.Dispose();
            boxPlane.Dispose();
            //returns the outputs
            var outInfo = new Dictionary <string, object>
            {
                { "bBox", bBox },
                { "boxCenter", boxCenter },
                { "boxOutline", boxSheetCurves }
            };

            return(outInfo);
        }
예제 #9
0
        private bool updatePositions(Autodesk.Revit.DB.ViewSheet curViewSheet)
        {
            Autodesk.Revit.DB.XYZ       norXYZ          = null;
            Autodesk.Revit.DB.XYZ       deltaXYZ        = null;
            Autodesk.Revit.DB.ElementId deltaViewportId = null;

            if (curViewSheet != null)
            {
                ICollection <ElementId> curViewportsIdsCollection = curViewSheet.GetAllViewports();
                foreach (ElementId curViewportId in curViewportsIdsCollection)
                {
                    if (this.selViewportsIdsAndPositions.ContainsKey(curViewportId))
                    {
                        Autodesk.Revit.DB.Viewport curViewport = doc.GetElement(curViewportId) as Autodesk.Revit.DB.Viewport;
                        if (curViewport != null)
                        {
                            norXYZ = curViewport.GetBoxCenter();
                            Autodesk.Revit.DB.XYZ preXYZ = this.selViewportsIdsAndPositions[curViewportId];
                            Autodesk.Revit.DB.XYZ curXYZ = curViewport.GetBoxCenter();

                            if ((curXYZ.X != preXYZ.X) || (curXYZ.Y != preXYZ.Y) || (curXYZ.Z != preXYZ.Z))
                            {
                                deltaViewportId = curViewportId;
                                deltaXYZ        = new XYZ((curXYZ.X - preXYZ.X), (curXYZ.Y - preXYZ.Y), (curXYZ.Z - preXYZ.Z));

                                break;
                            }
                        }
                    }
                }
            }

            if ((deltaXYZ != null) && (deltaViewportId != null))
            {
                List <ElementId> viewportIds            = new List <ElementId>(this.selViewportsIdsAndPositions.Keys);
                PageAlignmentToolRequestHandler handler = new PageAlignmentToolRequestHandler(norXYZ, deltaViewportId, viewportIds);
                ExternalEvent exEvent = ExternalEvent.Create(handler);
                exEvent.Raise();

                return(true);
            }

            return(false);
        }
예제 #10
0
        /// <summary>
        /// This node will set the child viewports box center given the parent viewport.
        /// </summary>
        /// <param name="parentViewport">Viewport to get location from.</param>
        /// <param name="childViewports">Viewports to set to location collected.</param>
        /// <returns name="childViewports">The viewports you moved.</returns>
        /// <search>
        /// viewport
        /// </search>
        public static List <global::Revit.Elements.Element> SetLocationBasedOnOther(global::Revit.Elements.Element parentViewport, List <global::Revit.Elements.Element> childViewports)
        {
            Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument;
            Autodesk.Revit.DB.Viewport internalViewport = (Autodesk.Revit.DB.Viewport)parentViewport.InternalElement;
            Autodesk.Revit.DB.XYZ      locationToUse    = internalViewport.GetBoxCenter();

            List <Autodesk.Revit.DB.Viewport> internalChildViewports = new List <Autodesk.Revit.DB.Viewport>();

            foreach (global::Revit.Elements.Element viewport in childViewports)
            {
                internalChildViewports.Add((Autodesk.Revit.DB.Viewport)viewport.InternalElement);
            }

            foreach (Autodesk.Revit.DB.Viewport vPort in internalChildViewports)
            {
                TransactionManager.Instance.EnsureInTransaction(doc);
                vPort.SetBoxCenter(locationToUse);
                TransactionManager.Instance.TransactionTaskDone();
            }

            return(childViewports);
        }
예제 #11
0
 /// <summary>
 /// This node will retrieve the viewport's box center.
 /// </summary>
 /// <param name="viewport">The viewport to set.</param>
 /// <returns name="boxCenter">The viewport's box center as a point.</returns>
 /// <search>
 /// viewport
 /// </search>
 public static Point BoxCenter(global::Revit.Elements.Element viewport)
 {
     Autodesk.Revit.DB.Viewport internalViewport = (Autodesk.Revit.DB.Viewport)viewport.InternalElement;
     return(internalViewport.GetBoxCenter().ToPoint());
 }
예제 #12
0
 public static Viewport Wrap(Autodesk.Revit.DB.Viewport ele, bool isRevitOwned)
 {
     return(Viewport.FromExisting(ele, isRevitOwned));
 }
예제 #13
0
 /// <summary>
 /// Initialize a Viewport element
 /// </summary>
 /// <param name="viewport"></param>
 private void InitViewport(Autodesk.Revit.DB.Viewport viewport)
 {
     InternalSetViewport(viewport);
 }
예제 #14
0
 /// <summary>
 /// Private constructor for the Element
 /// </summary>
 /// <param name="viewport"></param>
 private Viewport(Autodesk.Revit.DB.Viewport viewport)
 {
     SafeInit(() => InitViewport(viewport));
 }
예제 #15
0
 /// <summary>
 /// Set the Viewport property, element id, and unique id
 /// </summary>
 /// <param name="viewport"></param>
 private void InternalSetViewport(Autodesk.Revit.DB.Viewport viewport)
 {
     this.InternalViewport  = viewport;
     this.InternalElementId = viewport.Id;
     this.InternalUniqueId  = viewport.UniqueId;
 }