Skip to content

Commit

Permalink
update after comments
Browse files Browse the repository at this point in the history
  • Loading branch information
michal-pekacki committed Mar 6, 2023
1 parent a8aa9cf commit 364a620
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 57 deletions.
6 changes: 3 additions & 3 deletions Revit_Core_Engine/Create/View/Sheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ 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.")]
[Input("viewTemplateId", "The Title Block Id to be applied to the sheet.")]
[Output("newSheet", "The new sheet.")]
public static ViewSheet Sheet(this Document document, string sheetName, string sheetNumber, ElementId titleBlockId)
{
List<string> sheetNumbersInModel = new FilteredElementCollector(document).OfClass(typeof(ViewSheet)).WhereElementIsNotElementType().Select(x => (x as ViewSheet).SheetNumber).ToList();
List<string> sheetNumbersInModel = new FilteredElementCollector(document).OfClass(typeof(ViewSheet)).Cast<ViewSheet>().Select(x => x.SheetNumber).ToList();
ViewSheet newSheet = ViewSheet.Create(document, titleBlockId);

if (!string.IsNullOrEmpty(sheetName))
Expand All @@ -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.");
}
}

Expand Down
63 changes: 27 additions & 36 deletions Revit_Core_Engine/Create/View/ViewPlan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
{
Expand Down
15 changes: 1 addition & 14 deletions Revit_Core_Engine/Create/View/ViewReflectedCeilingPlan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions Revit_Core_Engine/Query/DrawingArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<BH.oM.Geometry.Point> { areaUpPoint, areaRightPoint, areaDownPoint, areaLeftPoint };
BoundingBox areaBox = areaPoints.Bounds();
Expand Down

0 comments on commit 364a620

Please sign in to comment.