Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Revit_Core_Engine/Convert/Revit/ToRevit/ViewPlan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static ViewPlan ToRevitViewPlan(this oM.Adapters.Revit.Elements.ViewPlan
viewTemplateId = viewPlanTemplate.Id;
}

revitViewPlan = Create.ViewPlan(document, level, viewPlan.ViewName, null, viewTemplateId) as ViewPlan;
revitViewPlan = Create.ViewPlan(document, level, viewPlan.ViewName, ViewFamily.FloorPlan, null as CurveLoop, viewTemplateId) as ViewPlan;

// Copy parameters from BHoM object to Revit element
revitViewPlan.CopyParameters(viewPlan, settings);
Expand Down
80 changes: 80 additions & 0 deletions Revit_Core_Engine/Create/View/Sheet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
*
*
* The BHoM is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3.0 of the License, or
* (at your option) any later version.
*
* The BHoM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

using Autodesk.Revit.DB;
using BH.oM.Base.Attributes;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;

namespace BH.Revit.Engine.Core
{
public static partial class Create
{
/***************************************************/
/**** Public Methods ****/
/***************************************************/

[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("titleBlockId", "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)
{
ViewSheet newSheet = null;

if (!string.IsNullOrEmpty(sheetNumber))
{
int number = 0;
string uniqueNumber = sheetNumber;

while (uniqueNumber.IsExistingSheetNumber(document))
{
number++;
uniqueNumber = $"{sheetNumber} ({number})";
}

newSheet = ViewSheet.Create(document, titleBlockId);
newSheet.SheetNumber = uniqueNumber;

if (uniqueNumber != sheetNumber)
{
BH.Engine.Base.Compute.RecordWarning($"Sheet named '{sheetNumber}' already exists in the document. Newly created has been named '{uniqueNumber}' instead.");
}
}

if (!string.IsNullOrEmpty(sheetName))
{
newSheet.Name = sheetName;
}

return newSheet;
}

/***************************************************/
}
}



100 changes: 77 additions & 23 deletions Revit_Core_Engine/Create/View/ViewPlan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
using System;
using System.ComponentModel;
using BH.oM.Base.Attributes;
using System.Collections.Generic;
using System.Linq;
using Autodesk.Revit.UI;

namespace BH.Revit.Engine.Core
{
Expand All @@ -33,67 +36,118 @@ public static partial class Create
/**** Public Methods ****/
/***************************************************/

[Description("Creates and returns a new Floor Plan view in the current Revit file.")]
[PreviousVersion("6.1", "BH.Revit.Engine.Core.Create.ViewPlan(Autodesk.Revit.DB.Document, Autodesk.Revit.DB.Level, System.String, Autodesk.Revit.DB.CurveLoop, Autodesk.Revit.DB.ElementId, Autodesk.Revit.DB.ViewDetailLevel)")]
[Description("Creates and returns a new Plan view in the current Revit file.")]
[Input("document", "Revit current document to be processed.")]
[Input("level", "The level that the created Floor Plan refers to.")]
[Input("viewName", "Optional, name of the new view.")]
[Input("viewName", "Name of the new view.")]
[Input("cropBox", "Optional, the crop region to attempt to apply to the newly created view.")]
[Input("viewTemplateId", "Optional, the View Template Id to be applied in the view.")]
[Input("viewDetailLevel", "Optional, the Detail Level of the view.")]
[Output("viewPlan", "The new view.")]
public static View ViewPlan(this Document document, Autodesk.Revit.DB.Level level, string viewName = null, CurveLoop cropBox = null, ElementId viewTemplateId = null, ViewDetailLevel viewDetailLevel = ViewDetailLevel.Coarse)
[Input("viewDetailLevel", "Optional, the Detail Level of the view.")]
[Input("cropRegionVisible", "True if the crop region should be visible.")]
[Input("annotationCrop", "True if the annotation crop should be visible.")]
[Output("newView", "The new view.")]
public static View ViewPlan(this Document document, Level level, string viewName, ViewFamily viewFamily = ViewFamily.FloorPlan, CurveLoop cropBox = null, ElementId viewTemplateId = null, ViewDetailLevel viewDetailLevel = ViewDetailLevel.Coarse, bool cropRegionVisible = false, bool annotationCrop = false)
{
View result = null;
View newView = null;

ViewFamilyType vft = Query.ViewFamilyType(document, ViewFamily.FloorPlan);
if (!(viewFamily == ViewFamily.FloorPlan || viewFamily == ViewFamily.CeilingPlan || viewFamily == ViewFamily.AreaPlan || viewFamily == ViewFamily.StructuralPlan))
{
BH.Engine.Base.Compute.RecordError($"Could not create View of type '{viewFamily}'. It has to be a FloorPlan, CeilingPlan, AreaPlan, or StructuralPlan ViewType.");
return newView;
}

ViewFamilyType viewFamilyType = Query.ViewFamilyType(document, viewFamily);

result = Autodesk.Revit.DB.ViewPlan.Create(document, vft.Id, level.Id);
newView = Autodesk.Revit.DB.ViewPlan.Create(document, viewFamilyType.Id, level.Id);

Modify.SetViewDetailLevel(result, viewDetailLevel);
if (viewDetailLevel != ViewDetailLevel.Undefined)
Modify.SetViewDetailLevel(newView, viewDetailLevel);

if (cropBox != null)
{
try
{
ViewCropRegionShapeManager vcrShapeMgr = result.GetCropRegionShapeManager();
result.CropBoxVisible = true;
ViewCropRegionShapeManager vcrShapeMgr = newView.GetCropRegionShapeManager();
newView.CropBoxVisible = true;
vcrShapeMgr.SetCropShape(cropBox);
}
catch (Exception)
{
BH.Engine.Base.Compute.RecordWarning("Could not create the Floor Plan with the provided crop box. Check if the crop box is a valid geometry and if the view's designated template accepts it to change.");
BH.Engine.Base.Compute.RecordWarning("Could not apply the provided crop box to newly created view. Check if the crop box is a valid geometry.");
}
}

if (viewTemplateId != null)
{
if (!(document.GetElement(viewTemplateId) as View).IsTemplate)
{
BH.Engine.Base.Compute.RecordWarning($"Could not apply the View Template of Id '{viewTemplateId}'. Please check if it's a valid View Template.");
return newView;
}

try
{
result.ViewTemplateId = viewTemplateId;
newView.ViewTemplateId = viewTemplateId;
}
catch (Exception)
{
BH.Engine.Base.Compute.RecordWarning("Could not apply the View Template of Id " + viewTemplateId + "'." + ". Please check if it's a valid ElementId.");
BH.Engine.Base.Compute.RecordWarning($"Could not apply the View Template of Id '{viewTemplateId}'. Please check if it's a valid ElementId.");
}
}

if (!string.IsNullOrEmpty(viewName))
{
newView.SetViewName(viewName, document);
}

if (!newView.get_Parameter(BuiltInParameter.VIEWER_CROP_REGION_VISIBLE).Set(cropRegionVisible ? 1 : 0))
BH.Engine.Base.Compute.RecordWarning($"Could not set the crop region visibility in the view. Parameter is ready-only.");

if (!newView.get_Parameter(BuiltInParameter.VIEWER_ANNOTATION_CROP_ACTIVE).Set(annotationCrop ? 1 : 0))
BH.Engine.Base.Compute.RecordWarning($"Could not set the annotation crop in the view. Parameter is ready-only.");

return newView;
}

/***************************************************/

[Description("Creates and returns a new Plan view in the current Revit file.")]
[Input("document", "The current Revit document to be processed.")]
[Input("level", "The level that the created view refers to.")]
[Input("viewName", "Name of the new view.")]
[Input("viewFamily", "View Family of the View Type. The default is FloorPlan.")]
[Input("scopeBoxId", "(Optional) A Scope Box Id to attempt to apply to the newly created view.")]
[Input("viewTemplateId", "(Optional) A View Template Id to be applied in the view.")]
[Input("viewDetailLevel", "Optional, the Detail Level of the view.")]
[Input("cropRegionVisible", "True if the crop region should be visible.")]
[Input("annotationCrop", "True if the annotation crop should be visible.")]
[Output("newView", "The new view.")]
public static View ViewPlan(this Document document, Level level, string viewName, ViewFamily viewFamily = ViewFamily.FloorPlan, ElementId scopeBoxId = null, ElementId viewTemplateId = null, ViewDetailLevel viewDetailLevel = ViewDetailLevel.Coarse, bool cropRegionVisible = false, bool annotationCrop = false)
{
View newView = ViewPlan(document, level, viewName, viewFamily, null as CurveLoop, viewTemplateId, viewDetailLevel, cropRegionVisible, annotationCrop);

if (scopeBoxId != null)
{
Element scopeBox = document.GetElement(scopeBoxId);

if (!((BuiltInCategory)scopeBox.Category.Id.IntegerValue == BuiltInCategory.OST_VolumeOfInterest))
{
BH.Engine.Base.Compute.RecordWarning($"Could not apply the Scope Box of Id '{scopeBoxId}'. Please check if it's a valid Scope Box element.");
return newView;
}

try
{
#if (REVIT2018 || REVIT2019)
result.ViewName = viewName;
#else
result.Name = viewName;
#endif
newView.get_Parameter(BuiltInParameter.VIEWER_VOLUME_OF_INTEREST_CROP).Set(scopeBoxId);
}
catch
catch (Exception)
{
BH.Engine.Base.Compute.RecordWarning("There is already a view named '" + viewName + "'." + " It has been named '" + result.Name + "' instead.");
BH.Engine.Base.Compute.RecordWarning($"Could not apply the Scope Box of Id '{scopeBoxId}'. Please check if it's a valid ElementId.");
}
}
return result;

return newView;
}

/***************************************************/
Expand Down
53 changes: 24 additions & 29 deletions Revit_Core_Engine/Create/View/ViewReflectedCeilingPlan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,72 +33,67 @@ public static partial class Create
/**** Public Methods ****/
/***************************************************/

[ToBeRemoved("6.1", "Calls to this method are to be replaced with Create.ViewPlan with 'viewFamily' parameter equal to ViewFamily.CeilingPlan.")]
[Description("Creates and returns a new Reflected Ceiling Plan view in the current Revit file.")]
[Input("document", "Revit current document to be processed.")]
[Input("level", "The level that the created Floor Plan refers to.")]
[Input("viewName", "Optional, name of the new view.")]
[Input("cropBox", "Optional, the crop region to attempt to apply to the newly created view.")]
[Input("viewTemplateId", "Optional, the View Template Id to be applied in the view.")]
[Input("viewDetailLevel", "Optional, the Detail Level of the view.")]
[Output("viewReflectedCeilingPlan", "The new view.")]
public static View ViewReflectedCeilingPlan(this Document document, Autodesk.Revit.DB.Level level, string viewName = null, CurveLoop cropBox = null, ElementId viewTemplateId = null, ViewDetailLevel viewDetailLevel = ViewDetailLevel.Coarse)
[Input("viewDetailLevel", "Optional, the Detail Level of the view.")]
[Output("viewReflectedCeilingPlan", "The new view.")]
public static View ViewReflectedCeilingPlan(this Document document, Level level, string viewName = null, CurveLoop cropBox = null, ElementId viewTemplateId = null, ViewDetailLevel viewDetailLevel = ViewDetailLevel.Coarse)
{
View result = null;
View newView = null;

ViewFamilyType vft = Query.ViewFamilyType(document, ViewFamily.CeilingPlan);
ViewFamilyType viewFamilyType = Query.ViewFamilyType(document, ViewFamily.CeilingPlan);

newView = Autodesk.Revit.DB.ViewPlan.Create(document, viewFamilyType.Id, level.Id);

Modify.SetViewDetailLevel(newView, viewDetailLevel);

result = Autodesk.Revit.DB.ViewPlan.Create(document, vft.Id, level.Id);

Modify.SetViewDetailLevel(result, viewDetailLevel);

if (cropBox != null)
{
try
{
ViewCropRegionShapeManager vcrShapeMgr = result.GetCropRegionShapeManager();
result.CropBoxVisible = true;
ViewCropRegionShapeManager vcrShapeMgr = newView.GetCropRegionShapeManager();
newView.CropBoxVisible = true;
vcrShapeMgr.SetCropShape(cropBox);
}
catch (Exception)
{
BH.Engine.Base.Compute.RecordWarning("Could not create the Reflected Ceiling Plan with the provided crop box. Check if the crop box is a valid geometry and if the view's designated template accepts it to change.");
BH.Engine.Base.Compute.RecordWarning("Could not create the Reflected Ceiling Plan with the provided crop box. Check if the crop box is a valid geometry.");
}
}

if (viewTemplateId != null)
{
if (!(document.GetElement(viewTemplateId) as View).IsTemplate)
{
BH.Engine.Base.Compute.RecordWarning("Could not apply the View Template of Id " + viewTemplateId + "'." + ". Please check if it's a valid View Template.");
return newView;
}

try
{
result.ViewTemplateId = viewTemplateId;
newView.ViewTemplateId = viewTemplateId;
}
catch (Exception)
{
BH.Engine.Base.Compute.RecordWarning("Could not apply the View Template of Id " + viewTemplateId + "'." + ". Please check if it's a valid ElementId.");
}
}

if (!string.IsNullOrEmpty(viewName))
{
try
{
#if (REVIT2018 || REVIT2019)
result.ViewName = viewName;
#else
result.Name = viewName;
#endif
}
catch
{
BH.Engine.Base.Compute.RecordWarning("There is already a view named '" + viewName + "'." + " It has been named '" + result.Name + "' instead.");
}
newView.SetViewName(viewName, document);
}
return result;

return newView;
}

/***************************************************/
}
}



Loading