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) { View result = null; ViewFamilyType vft = Query.ViewFamilyType(document, ViewFamily.FloorPlan); 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; vcrShapeMgr.SetCropShape(cropBox); } catch (Exception) { BH.Engine.Reflection.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."); } } if (viewTemplateId != null) { try { result.ViewTemplateId = viewTemplateId; } catch (Exception) { BH.Engine.Reflection.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.Reflection.Compute.RecordWarning("There is already a view named '" + viewName + "'." + " It has been named '" + result.Name + "' instead."); } } return(result); }
public static View ViewSection(this Document document, Autodesk.Revit.DB.BoundingBoxXYZ boundingBoxXyz, string viewName = null, ElementId viewTemplateId = null, ViewDetailLevel viewDetailLevel = ViewDetailLevel.Coarse) { View result = null; ViewFamilyType vft = Query.ViewFamilyType(document, ViewFamily.Section); result = Autodesk.Revit.DB.ViewSection.CreateSection(document, vft.Id, boundingBoxXyz); Modify.SetViewDetailLevel(result, viewDetailLevel); if (viewTemplateId != null) { try { result.ViewTemplateId = viewTemplateId; } catch (Exception) { BH.Engine.Reflection.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.Reflection.Compute.RecordWarning("There is already a view named '" + viewName + "'." + " It has been named '" + result.Name + "' instead."); } } return(result); }
public static View View3D(this Document document, string viewName = null, BoundingBoxXYZ boundingBoxXyz = null, ViewOrientation3D viewOrientation3D = null, ElementId viewTemplateId = null, ViewDetailLevel viewDetailLevel = ViewDetailLevel.Coarse) { //for information about a perspective boundingbox and its orientation see here: //https://knowledge.autodesk.com/support/revit-products/learn-explore/caas/CloudHelp/cloudhelp/2014/ENU/Revit/files/GUID-A7FA8DBC-830E-482D-9B66-147399524442-htm.html View3D result = null; ViewFamilyType vft = Query.ViewFamilyType(document, ViewFamily.ThreeDimensional); result = Autodesk.Revit.DB.View3D.CreatePerspective(document, vft.Id); Modify.SetViewDetailLevel(result, viewDetailLevel); if (!string.IsNullOrEmpty(viewName)) { try { #if (REVIT2018 || REVIT2019) result.ViewName = viewName; #else result.Name = viewName; #endif } catch { BH.Engine.Reflection.Compute.RecordWarning("There is already a view named '" + viewName + "'." + " It has been named '" + result.Name + "' instead."); } } if (viewTemplateId != null) { try { result.ViewTemplateId = viewTemplateId; } catch (Exception) { BH.Engine.Reflection.Compute.RecordWarning("Could not apply the View Template of Id " + viewTemplateId + "'." + ". Please check if it's a valid ElementId."); } } if (viewOrientation3D != null) { try { result.SetOrientation(viewOrientation3D); } catch (Exception) { BH.Engine.Reflection.Compute.RecordWarning("Could not set the view's orientation in 3D due to unexpected values, please report this error."); } } if (boundingBoxXyz != null) { try { //transform to view coordinates previously picked points BoundingBoxXYZ bb = result.get_BoundingBox(result); Transform transform = bb.Transform; bb.Max = transform.Inverse.OfPoint(boundingBoxXyz.Max); bb.Min = transform.Inverse.OfPoint(boundingBoxXyz.Min); result.CropBox = bb; //changes the view's far clip to the the eye and target line's length (x1.5 offset) result.SetParameter(BuiltInParameter.VIEWER_BOUND_OFFSET_FAR, boundingBoxXyz.Min.DistanceTo(boundingBoxXyz.Max) * 1.5); } catch (Exception) { BH.Engine.Reflection.Compute.RecordWarning("Could not set the view's bounding box due to unexpected values, please report this error."); } } return(result); }