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); }
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); } } } } } } }
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); }
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); }
/// <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); }
/// <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()); }