/// <summary> /// Utility node to double check how many plan circuits exist, and where they are located. /// </summary> /// <param name="view">The view to check.</param> /// <returns></returns> public static List <Autodesk.DesignScript.Geometry.Point> GetCircuitPoints(Revit.Elements.Views.FloorPlanView view) { var dDoc = DocumentManager.Instance.CurrentDBDocument; var cDoc = dDoc.Create; // Extract the Revit objects from the view and room var iView = view.InternalElement as Autodesk.Revit.DB.ViewPlan; // Get the target topology and plan circuits var topology = dDoc.get_PlanTopology(iView.GenLevel); var circuits = topology.Circuits; var points = new List <Autodesk.DesignScript.Geometry.Point>(); var borders = new List <Autodesk.DesignScript.Geometry.Curve>(); foreach (PlanCircuit pc in circuits) { Autodesk.Revit.DB.UV uv = pc.GetPointInside(); var newU = UnitUtils.ConvertFromInternalUnits(uv.U, DisplayUnitType.DUT_MILLIMETERS); var newV = UnitUtils.ConvertFromInternalUnits(uv.V, DisplayUnitType.DUT_MILLIMETERS); //Autodesk.Revit.DB.XYZ xyz = new XYZ(uv.U, uv.V, baseLevel.Elevation); points.Add(Autodesk.DesignScript.Geometry.Point.ByCoordinates(newU, newV)); } return(points); }
public static PathOfTravel[] LongestOfShortestExitPaths(Revit.Elements.Views.FloorPlanView floorPlan, Autodesk.DesignScript.Geometry.Point[] endPtsList) { if (floorPlan == null) { throw new ArgumentNullException("floorPlan", Properties.Resources.InvalidView); } if (endPtsList == null) { throw new ArgumentNullException("endPtList", Properties.Resources.InvalidEndPointList); } if (!endPtsList.Any()) { throw new ArgumentException(Properties.Resources.EndPointListEmpty, "endPtList"); } if (endPtsList.Any(x => x == null)) { throw new ArgumentException(Properties.Resources.EndPointListHasNulls, "endPtList"); } // Check that floor has some rooms Rvt.Document doc = DocumentManager.Instance.CurrentDBDocument; if (doc == null) { throw new ArgumentException(Properties.Resources.RoomsForLongestPathNotFound); } FilteredElementCollector collector = new Rvt.FilteredElementCollector(doc).OfCategory(Rvt.BuiltInCategory.OST_Rooms); if (collector.ToElements().Count() == 0) { throw new ArgumentException(Properties.Resources.RoomsForLongestPathNotFound); } return(InternalLongestOfShortestExitPaths( (Rvt.View)floorPlan.InternalElement, endPtsList.Select(x => x.ToXyz()))); }
public static List <Autodesk.Revit.DB.FamilyInstance> ByCurve(List <Autodesk.DesignScript.Geometry.Curve> Curve, string FamilyName, string FamilyType, Revit.Elements.Views.FloorPlanView DestinationView) { var doc = DocumentManager.Instance.CurrentDBDocument; List <Autodesk.Revit.DB.FamilyInstance> famColl = new List <Autodesk.Revit.DB.FamilyInstance>(); ElementId viewId = Spring.Elements.UnwrapElement(DestinationView); View finalView = doc.GetElement(viewId) as View; FamilySymbol symbol = Elements.GetSymbol(doc, FamilyName, FamilyType); try { TransactionManager.Instance.EnsureInTransaction(doc); foreach (Autodesk.DesignScript.Geometry.Curve i in Curve) { Line j = i.ToRevitType() as Line; Autodesk.Revit.DB.FamilyInstance instance = doc.Create.NewFamilyInstance(j, symbol, finalView); instance.ToDSType(true); famColl.Add(instance); } ; TransactionManager.Instance.TransactionTaskDone(); return(famColl); } catch (Exception ex) { throw ex; } }
public static PathOfTravel[] ByFloorPlanPoints(Revit.Elements.Views.FloorPlanView floorPlan, Autodesk.DesignScript.Geometry.Point[] startPtList, Autodesk.DesignScript.Geometry.Point[] endPtList, bool manyToMany) { if (floorPlan == null) { throw new ArgumentNullException(Properties.Resources.InvalidView); } if (startPtList == null) { throw new ArgumentNullException(Properties.Resources.InvalidStartPointList); } if (endPtList == null) { throw new ArgumentNullException(Properties.Resources.InvalidEndPointList); } if (!startPtList.Any()) { throw new ArgumentNullException(Properties.Resources.StartPointListEmpty); } if (!endPtList.Any()) { throw new ArgumentNullException(Properties.Resources.EndPointListEmpty); } if (startPtList.Any(x => x == null)) { throw new ArgumentException(Properties.Resources.StartPointListHasNulls); } if (endPtList.Any(x => x == null)) { throw new ArgumentException(Properties.Resources.EndPointListHasNulls); } if (!manyToMany && (startPtList.Count() != endPtList.Count())) { throw new ArgumentException(Properties.Resources.StartEndListSizeMismatch); } if (manyToMany) { // although there is the many-to-many version of PathOfTravel creation API (the "mapped" version), the fact that some elements // need to be reused between the node runs makes it difficult to use (see UpdateReusedElements, DeleteExtraElements and CreateAdditionalElements) // so it's easier to flatten the lists manually and always use the same ("non-mapped") version of the API List <Autodesk.DesignScript.Geometry.Point> newStartPointList = new List <Autodesk.DesignScript.Geometry.Point>(); List <Autodesk.DesignScript.Geometry.Point> newEndPointList = new List <Autodesk.DesignScript.Geometry.Point>(); foreach (var endPt in endPtList) { foreach (var startPt in startPtList) { newStartPointList.Add(startPt); newEndPointList.Add(endPt); } } startPtList = newStartPointList.ToArray(); endPtList = newEndPointList.ToArray(); } return(InternalByViewEndPoints( (Rvt.View)floorPlan.InternalElement, startPtList.Select(x => x.ToXyz()), endPtList.Select(x => x.ToXyz()))); }
public static Dictionary <string, dynamic> CopyBordersToView(Revit.Elements.Room room, Revit.Elements.Views.FloorPlanView view) { var dDoc = DocumentManager.Instance.CurrentDBDocument; var cDoc = dDoc.Create; // Construct the return dictionary var returnDict = new Dictionary <string, dynamic>() { { "Room", room }, { "View", view }, { "Curves", null } }; // Extract the Revit objects from the view and room var iView = view.InternalElement as Autodesk.Revit.DB.ViewPlan; var iRoom = room.InternalElement as Autodesk.Revit.DB.Architecture.Room; // Retrieve the target level for the rooms var targetLevel = iView.GenLevel; var baseLevel = iRoom.Level; // Calculate how much the curves should be moved double distanceToMove = targetLevel.Elevation - baseLevel.Elevation; // Convert to a real unit double distanceInScience = UnitUtils.ConvertFromInternalUnits(distanceToMove, DisplayUnitType.DUT_MILLIMETERS); // Create an origin for the plane on which to project the room borders, and create the plane var newOrigin = Autodesk.DesignScript.Geometry.Point.ByCoordinates(0, 0, distanceInScience); var projPlane = Autodesk.DesignScript.Geometry.Plane.ByOriginNormal(newOrigin, Vector.ZAxis()); // Extract room borders using the Revit Nodes method var borders = room.CenterBoundary; var projectedBorders = new List <List <Autodesk.DesignScript.Geometry.Curve> >(); List <CurveArray> lca = new List <CurveArray>(); // Extract revit curves and project them to the new level (it works without the projection but produces strange behaviour) foreach (IEnumerable <Autodesk.DesignScript.Geometry.Curve> enumerable in borders) { var newList = new List <Autodesk.DesignScript.Geometry.Curve>(); projectedBorders.Add(newList); CurveArray ca = new CurveArray(); lca.Add(ca); foreach (Autodesk.DesignScript.Geometry.Curve curve in enumerable) { var movedCurve = curve.Translate(Vector.ZAxis(), distanceInScience) as Autodesk.DesignScript.Geometry.Curve; //var projectedCurves = curve.Project(projPlane, Vector.ZAxis())[0] as Autodesk.DesignScript.Geometry.Curve; newList.Add(movedCurve); ca.Append(movedCurve.ToRevitType()); } } // Add the curves to the output dict returnDict["Curves"] = projectedBorders; // Extract the target SketchPlane var mySketch = (view.InternalElement as ViewPlan).SketchPlane; // Create the new room boundaries TransactionManager.Instance.EnsureInTransaction(dDoc); foreach (CurveArray ca in lca) { cDoc.NewRoomBoundaryLines(mySketch, ca, view.InternalElement as View); } TransactionManager.Instance.TransactionTaskDone(); return(returnDict); }
/// <summary> /// Moves the rooms from one level to another. NOTE: This node produces an error about the room having a negative height, but by pressing "Adjust Limits..." the rooms will be moved correctly. /// </summary> /// <param name="room">The room to move.</param> /// <param name="view">The target view (level) to move to.</param> /// <returns></returns> public static Revit.Elements.Room ChangeLevel(Revit.Elements.Room room, Revit.Elements.Views.FloorPlanView view) { var dDoc = DocumentManager.Instance.CurrentDBDocument; var cDoc = dDoc.Create; // Extract the Revit objects from the view and room var iView = view.InternalElement as Autodesk.Revit.DB.ViewPlan; var iRoom = room.InternalElement as Autodesk.Revit.DB.Architecture.Room; // Retrieve the target level for the rooms var targetLevel = iView.GenLevel; var baseLevel = iRoom.Level; // For testing purposes var returnList = new List <dynamic>(); // Get the target topology and plan circuits var topology = dDoc.get_PlanTopology(targetLevel); var circuits = topology.Circuits; /* Match the old room position with the new one */ bool targetFound = false; PlanCircuit targetPC = null; foreach (PlanCircuit pc in circuits) { Autodesk.Revit.DB.UV uv = pc.GetPointInside(); Autodesk.Revit.DB.XYZ xyz = new XYZ(uv.U, uv.V, baseLevel.Elevation); targetFound = iRoom.IsPointInRoom(xyz); if (targetFound) { targetPC = pc; break; } } if (!targetFound) { return(null); } /* Unplace the old room */ TransactionManager.Instance.EnsureInTransaction(dDoc); iRoom.Unplace(); TransactionManager.Instance.TransactionTaskDone(); /* Place the new room */ TransactionManager.Instance.EnsureInTransaction(dDoc); var newRoom = cDoc.NewRoom(iRoom, targetPC); TransactionManager.Instance.TransactionTaskDone(); //dDoc.Regenerate(); return(newRoom.ToDSType(true) as Revit.Elements.Room); }