diff --git a/Revit_Core_Engine/Create/View/Sheet.cs b/Revit_Core_Engine/Create/View/Sheet.cs index 03328876f..a362017a8 100644 --- a/Revit_Core_Engine/Create/View/Sheet.cs +++ b/Revit_Core_Engine/Create/View/Sheet.cs @@ -34,7 +34,7 @@ public static partial class Create /**** Public Methods ****/ /***************************************************/ - [Description("Creates and returns a new Floor Plan view in the current Revit file.")] + [Description("Creates and returns a new Sheet in the current Revit file.")] [Input("document", "The current Revit document to be processed.")] [Input("sheetName", "Name of the new sheet.")] [Input("sheetNumber", "Number of the new sheet.")] @@ -42,7 +42,7 @@ public static partial class Create [Output("newSheet", "The new sheet.")] public static ViewSheet Sheet(this Document document, string sheetName, string sheetNumber, ElementId titleBlockId) { - List sheetNumbersInModel = new FilteredElementCollector(document).OfClass(typeof(ViewSheet)).WhereElementIsNotElementType().Select(x => (x as ViewSheet).SheetNumber).ToList(); + List sheetNumbersInModel = new FilteredElementCollector(document).OfClass(typeof(ViewSheet)).Cast().Select(x => x.SheetNumber).ToList(); ViewSheet newSheet = ViewSheet.Create(document, titleBlockId); if (!string.IsNullOrEmpty(sheetName)) @@ -64,7 +64,7 @@ public static ViewSheet Sheet(this Document document, string sheetName, string s newSheet.SheetNumber = uniqueNumber; if (uniqueNumber != sheetNumber) { - BH.Engine.Base.Compute.RecordWarning($"There is already a sheet named '{sheetNumber}'. It has been named '{uniqueNumber}' instead."); + BH.Engine.Base.Compute.RecordWarning($"Sheet named '{sheetNumber}' already exists in the document. Newly created has been named '{uniqueNumber}' instead."); } } diff --git a/Revit_Core_Engine/Create/View/ViewPlan.cs b/Revit_Core_Engine/Create/View/ViewPlan.cs index a8edde747..d056a0cf1 100644 --- a/Revit_Core_Engine/Create/View/ViewPlan.cs +++ b/Revit_Core_Engine/Create/View/ViewPlan.cs @@ -88,24 +88,7 @@ public static View ViewPlan(this Document document, Level level, string viewName if (!string.IsNullOrEmpty(viewName)) { - int number = 0; - string uniqueName = viewName; - - while (uniqueName.IsExistingViewName(document)) - { - number++; - uniqueName = $"{viewName} ({number})"; - } - -#if (REVIT2018 || REVIT2019) - newView.ViewName = uniqueName; -#else - newView.Name = uniqueName; -#endif - if (uniqueName != viewName) - { - BH.Engine.Base.Compute.RecordWarning($"There is already a view named '{viewName}'. It has been named '{uniqueName}' instead."); - } + newView.SetViewName(viewName, document); } return newView; @@ -157,24 +140,7 @@ public static View ViewPlan(this Document document, Level level, string viewName if (!string.IsNullOrEmpty(viewName)) { - int number = 0; - string uniqueName = viewName; - - while (uniqueName.IsExistingViewName(document)) - { - number++; - uniqueName = $"{viewName} ({number})"; - } - -#if (REVIT2018 || REVIT2019) - newView.ViewName = uniqueName; -#else - newView.Name = uniqueName; -#endif - if (uniqueName != viewName) - { - BH.Engine.Base.Compute.RecordWarning($"There is already a view named '{viewName}'. It has been named '{uniqueName}' instead."); - } + newView.SetViewName(viewName, document); } if (scopeBoxId != null) @@ -207,6 +173,31 @@ public static View ViewPlan(this Document document, Level level, string viewName /**** Private Methods ****/ /***************************************************/ + [Description("Set View Name to the given value. If the view name already exists in the model, a number suffix is added.")] + private static void SetViewName(this View view, string viewName, Document document) + { + int number = 0; + string uniqueName = viewName; + + while (uniqueName.IsExistingViewName(document)) + { + number++; + uniqueName = $"{viewName} ({number})"; + } + +#if (REVIT2018 || REVIT2019) + view.ViewName = uniqueName; +#else + view.Name = uniqueName; +#endif + if (uniqueName != viewName) + { + BH.Engine.Base.Compute.RecordWarning($"There is already a view named '{viewName}'. It has been named '{uniqueName}' instead."); + } + } + + /***************************************************/ + [Description("Check if given view name exists in the Revit model.")] private static bool IsExistingViewName(this string viewName, Document document) { diff --git a/Revit_Core_Engine/Create/View/ViewReflectedCeilingPlan.cs b/Revit_Core_Engine/Create/View/ViewReflectedCeilingPlan.cs index 59a317685..0447df486 100644 --- a/Revit_Core_Engine/Create/View/ViewReflectedCeilingPlan.cs +++ b/Revit_Core_Engine/Create/View/ViewReflectedCeilingPlan.cs @@ -85,20 +85,7 @@ public static View ViewReflectedCeilingPlan(this Document document, Level level, if (!string.IsNullOrEmpty(viewName)) { - int number = 0; - string uniqueName = viewName; - - while (uniqueName.IsExistingViewName(document)) - { - number++; - uniqueName = $"{viewName} ({number})"; - } - - newView.get_Parameter(BuiltInParameter.VIEW_NAME).Set(uniqueName); - if (uniqueName != viewName) - { - BH.Engine.Base.Compute.RecordWarning($"There is already a view named '{viewName}'. It has been named '{uniqueName}' instead."); - } + newView.SetViewName(viewName, document); } return newView; diff --git a/Revit_Core_Engine/Query/DrawingArea.cs b/Revit_Core_Engine/Query/DrawingArea.cs index 5b9c52305..0ca76ffd4 100644 --- a/Revit_Core_Engine/Query/DrawingArea.cs +++ b/Revit_Core_Engine/Query/DrawingArea.cs @@ -85,10 +85,10 @@ public static Outline DrawingArea(this Document document, FamilySymbol titleBloc leftPoints.Add(leftPoint); } - var areaUpPoint = upPoints.OrderBy(x => x.Distance(centrePoint)).FirstOrDefault(); - var areaRightPoint = rightPoints.OrderBy(x => x.Distance(centrePoint)).FirstOrDefault(); - var areaDownPoint = downPoints.OrderBy(x => x.Distance(centrePoint)).FirstOrDefault(); - var areaLeftPoint = leftPoints.OrderBy(x => x.Distance(centrePoint)).FirstOrDefault(); + var areaUpPoint = upPoints.OrderBy(x => x.Y).FirstOrDefault(); + var areaRightPoint = rightPoints.OrderBy(x => x.X).FirstOrDefault(); + var areaDownPoint = downPoints.OrderByDescending(x => x.Y).FirstOrDefault(); + var areaLeftPoint = leftPoints.OrderByDescending(x => x.X).FirstOrDefault(); var areaPoints = new List { areaUpPoint, areaRightPoint, areaDownPoint, areaLeftPoint }; BoundingBox areaBox = areaPoints.Bounds();