/// <summary> /// Duplciates a view and renames it. /// </summary> /// <param name="Name">The name of the duplicated view</param> /// <param name="SourceView">The view to duplicate</param> /// <param name="DuplicateOptions">Enum ViewDuplicateOptions</param> /// <returns name="View">The duplicated view</returns> public static dynaView DuplicateView(string Name, dynaView SourceView, revitDB.ViewDuplicateOption DuplicateOptions) { string transactionName = "Duplicate View"; Func <revitView, revitDB.ViewDuplicateOption, revitDoc, revitView> dupView = (v, vdo, doc) => { revitElemId viewId = v.Duplicate(vdo); revitView newView = (revitView)doc.GetElement(viewId); newView.Name = Name; return(newView); }; revitView rView = (revitView)SourceView.InternalElement; revitDoc document = rView.Document; revitView view; if (document.IsModifiable) { TransactionManager.Instance.EnsureInTransaction(document); view = dupView(rView, DuplicateOptions, document); TransactionManager.Instance.TransactionTaskDone(); } else { using (Autodesk.Revit.DB.Transaction trans = new Autodesk.Revit.DB.Transaction(document)) { trans.Start(transactionName); view = dupView(rView, DuplicateOptions, document); trans.Commit(); } } return((dynaView)view.ToDSType(true)); }
/// <summary> /// Construct a Revit FilledRegion element by Curves /// </summary> /// <param name="view">View to place filled region on</param> /// <param name="boundary">Boundary curves</param> /// <param name="regionType">Region Type</param> /// <returns></returns> public static FilledRegion ByCurves(Revit.Elements.Views.View view, IEnumerable <Autodesk.DesignScript.Geometry.Curve> boundary, FilledRegionType regionType) { Autodesk.Revit.DB.FilledRegionType type = regionType.InternalRevitElement; CurveLoop loop = new CurveLoop(); foreach (Autodesk.DesignScript.Geometry.Curve curve in boundary) { loop.Append(curve.ToRevitType()); } if (loop.IsOpen()) { throw new Exception(Properties.Resources.CurveLoopNotClosed); } Autodesk.Revit.DB.View revitView = (Autodesk.Revit.DB.View)view.InternalElement; if (!view.IsAnnotationView()) { throw new Exception(Properties.Resources.ViewDoesNotSupportAnnotations); } return(new FilledRegion(revitView, type.Id, new List <CurveLoop>() { loop })); }
/// <summary> /// Construct a Revit DetailCurve element from a curve /// </summary> /// <param name="view">View to place the detail curve on</param> /// <param name="curve">Curve to create detailcurve from</param> /// <returns></returns> public static DetailCurve ByCurve(Revit.Elements.Views.View view, Autodesk.DesignScript.Geometry.Curve curve) { if (!view.IsAnnotationView()) { throw new Exception(Properties.Resources.ViewDoesNotSupportAnnotations); } if (!curve.IsPlanar) { throw new Exception(Properties.Resources.CurveIsNotPlanar); } if (curve is Autodesk.DesignScript.Geometry.PolyCurve) { throw new Exception(Properties.Resources.PolyCurvesConversionError); } // Pull Curve onto the XY plane to place it correctly on the view. Autodesk.DesignScript.Geometry.Plane XYplane = Autodesk.DesignScript.Geometry.Plane.XY(); Autodesk.DesignScript.Geometry.Curve flattenedCurve = curve.PullOntoPlane(XYplane); Autodesk.Revit.DB.View revitView = (Autodesk.Revit.DB.View)view.InternalElement; return(new DetailCurve(revitView, flattenedCurve.ToRevitType())); }
/// <summary> /// Show a colored Point Analysis Display in the Revit view. /// </summary> /// <param name="view">The view into which you want to draw the analysis results.</param> /// <param name="data">A list of PointAnalysisData objects.</param> /// <param name="name">An optional analysis results name to show on the results legend.</param> /// <param name="description">An optional analysis results description to show on the results legend.</param> /// <param name="unitType">An optional Unit type to provide conversions in the analysis results.</param> /// <returns>An PointAnalysisDisplay object.</returns> public static PointAnalysisDisplay ByViewAndPointAnalysisData(View view, PointAnalysisData[] data, string name = "", string description = "", Type unitType = null) { if (view == null) { throw new ArgumentNullException("view"); } if (data == null) { throw new ArgumentNullException("data"); } if (!data.Any()) { throw new Exception("There is no input data."); } if (string.IsNullOrEmpty(name)) { name = Resource1.AnalysisResultsDefaultName; } if (string.IsNullOrEmpty(description)) { description = Resource1.AnalysisResultsDefaultDescription; } return(new PointAnalysisDisplay(view.InternalView, data, name, description, unitType)); }
/// <summary> /// Creates a new View Callout. /// </summary> /// <param name="view">View to create the Callout in.</param> /// <param name="referenceView">View to set as Reference.</param> /// <param name="extents">Extents of the Callout as Rectangle.</param> /// <returns name="view">New Callout View.</returns> /// <search>view, create, callout, reference</search> public static View CreateReferenceCallout(View view, View referenceView, Rectangle extents) { var doc = DocumentManager.Instance.CurrentDBDocument; var v = (Autodesk.Revit.DB.View)view.InternalElement; var rv = (Autodesk.Revit.DB.View)referenceView.InternalElement; var pt1 = extents.BoundingBox.MinPoint.ToXyz(); var pt2 = extents.BoundingBox.MaxPoint.ToXyz(); TransactionManager.Instance.EnsureInTransaction(doc); switch (v.ViewType) { case Autodesk.Revit.DB.ViewType.FloorPlan: case Autodesk.Revit.DB.ViewType.CeilingPlan: case Autodesk.Revit.DB.ViewType.Elevation: case Autodesk.Revit.DB.ViewType.Section: case Autodesk.Revit.DB.ViewType.Detail: Autodesk.Revit.DB.ViewSection.CreateReferenceCallout(doc, v.Id, rv.Id, pt1, pt2); break; default: throw new ArgumentOutOfRangeException(nameof(view)); } TransactionManager.Instance.TransactionTaskDone(); return(view); }
public static List <Revit.Elements.Element> CopyPasteFilter(Revit.Elements.Views.View ViewToCopy, List <Revit.Elements.Views.View> ViewToPaste) { var filtersId = new List <ElementId>(); var settings = new List <OverrideGraphicSettings>(); var visibility = new List <Boolean>(); var Views = new List <Revit.Elements.Element>(); var viewtocopy = (Autodesk.Revit.DB.View)ViewToCopy.InternalElement; foreach (var id in viewtocopy.GetFilters()) { filtersId.Add(id); settings.Add(viewtocopy.GetFilterOverrides(id)); visibility.Add(viewtocopy.GetFilterVisibility(id)); } TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument); foreach (var pview in ViewToPaste) { var pasteview = (Autodesk.Revit.DB.View)pview.InternalElement; foreach (var i in filtersId.Zip(settings, Tuple.Create)) { pasteview.SetFilterOverrides(i.Item1, i.Item2); } foreach (var j in filtersId.Zip(visibility, Tuple.Create)) { pasteview.SetFilterVisibility(j.Item1, j.Item2); } Views.Add(pview); } TransactionManager.Instance.TransactionTaskDone(); return(Views); }
/// <summary> /// Construct a Revit Linear Dimension from at least two ElementGeometryReference. /// </summary> /// <param name="view">View to place dimension in</param> /// <param name="referenceGeometries">References to dimension, e.g. ElementCurveReference and ElementFaceReference</param> /// <param name="line">location of the dimension</param> /// <param name="suffix">Suffix</param> /// <param name="prefix">Prefix</param> /// <returns></returns> public static Dimension ByReferences(Revit.Elements.Views.View view, IEnumerable <Revit.GeometryReferences.ElementGeometryReference> referenceGeometries, Autodesk.DesignScript.Geometry.Line line, string suffix = "", string prefix = "") { var geometries = referenceGeometries.ToList(); if (geometries.Count < 2) { throw new Exception(string.Format(Properties.Resources.NotEnoughDataError, "ElementGeometryReference")); } Autodesk.Revit.DB.View revitView = (Autodesk.Revit.DB.View)view.InternalElement; if (!view.IsAnnotationView()) { throw new Exception(Properties.Resources.ViewDoesNotSupportAnnotations); } Line revitLine = (Line)line.ToRevitType(true); ReferenceArray array = new ReferenceArray(); foreach (var geo in geometries) { array.Append(geo.InternalReference); } return(new Dimension(revitView, revitLine, array, suffix, prefix)); }
/// <summary> /// /// </summary> /// <param name="view"></param> /// <param name="curves"></param> /// <returns></returns> public static View SetCropBoxByCurves(View view, List <Curve> curves) { if (!(view.InternalElement is Autodesk.Revit.DB.View v)) { throw new ArgumentNullException(nameof(view)); } if (curves == null || !curves.Any()) { throw new ArgumentNullException(nameof(curves)); } var doc = DocumentManager.Instance.CurrentDBDocument; var shapeManager = v.GetCropRegionShapeManager(); var cLoop = new Autodesk.Revit.DB.CurveLoop(); foreach (var curve in curves) { cLoop.Append(curve.ToRevitType()); } TransactionManager.Instance.EnsureInTransaction(doc); v.CropBoxActive = true; v.CropBoxVisible = true; shapeManager.SetCropShape(cLoop); TransactionManager.Instance.TransactionTaskDone(); return(view); }
/// <summary> /// Create a Revit Tag for a Revit Element at an offset location /// from the element's view extents /// </summary> /// <param name="view">View to tag in</param> /// <param name="element">Element to tag</param> /// <param name="horizontal">Optional: Place tag horizontal, /// defaults to true</param> /// <param name="addLeader">Optional: Add a leader, defaults to false</param> /// <param name="offset">Optional: Offset Vector, defaults to 0,0,0</param> /// <param name="horizontalAlignment">Optional: Horizontal Alignment /// within the element's extents, defaults to Center</param> /// <param name="verticalAlignment">Optional: Vertical Alignment /// within the element's extents, defaults to Middle</param> /// <returns></returns> /// <search> /// tagelement,annotate,documentation,tagoffset,movetag /// </search> public static Tag ByElementAndOffset(Revit.Elements.Views.View view, Element element, [DefaultArgument("Autodesk.DesignScript.Geometry.Vector.ByCoordinates(0,0,0)")] Autodesk.DesignScript.Geometry.Vector offset, string horizontalAlignment = "Center", string verticalAlignment = "Middle", bool horizontal = true, bool addLeader = false) { Autodesk.Revit.DB.HorizontalAlignmentStyle horizontalAlignmentStyle = HorizontalAlignmentStyle.Center; if (!Enum.TryParse <Autodesk.Revit.DB.HorizontalAlignmentStyle>(horizontalAlignment, out horizontalAlignmentStyle)) { horizontalAlignmentStyle = HorizontalAlignmentStyle.Center; } Autodesk.Revit.DB.VerticalAlignmentStyle verticalAlignmentStyle = VerticalAlignmentStyle.Middle; if (!Enum.TryParse <Autodesk.Revit.DB.VerticalAlignmentStyle>(verticalAlignment, out verticalAlignmentStyle)) { verticalAlignmentStyle = VerticalAlignmentStyle.Middle; } Autodesk.Revit.DB.View revitView = (Autodesk.Revit.DB.View)view.InternalElement; // Tagging elements by element category Autodesk.Revit.DB.TagMode tagMode = TagMode.TM_ADDBY_CATEGORY; Autodesk.Revit.DB.TagOrientation orientation = (horizontal) ? TagOrientation.Horizontal : TagOrientation.Vertical; if (!view.IsAnnotationView()) { throw new Exception(Properties.Resources.ViewDoesNotSupportAnnotations); } XYZ location = GetExtentsWithOffset(element, revitView, offset.ToRevitType(true), verticalAlignmentStyle, horizontalAlignmentStyle); return(new Tag(revitView, element.InternalElement, orientation, tagMode, addLeader, location)); }
public static FaceAnalysisDisplay ByViewAndFaceAnalysisData( View view, SurfaceData data, string name = "", string description = "", Type unitType = null) { if (view == null) { throw new ArgumentNullException("view"); } if (data == null) { throw new ArgumentNullException("data"); } if (string.IsNullOrEmpty(name)) { name = Properties.Resources.AnalysisResultsDefaultName; } if (string.IsNullOrEmpty(description)) { description = Properties.Resources.AnalysisResultsDefaultDescription; } return(new FaceAnalysisDisplay(view.InternalView, data, name, description, unitType)); }
/// <summary> /// Check if View is placed on a Sheet. /// </summary> /// <param name="view">View to check.</param> /// <returns>True if View is on Sheet, otherwise False.</returns> /// <search>isOnSheet, is on sheet</search> public static bool IsOnSheet(View view) { var doc = DocumentManager.Instance.CurrentDBDocument; var v = (Autodesk.Revit.DB.View)view.InternalElement; switch (v.ViewType) { case Autodesk.Revit.DB.ViewType.Undefined: case Autodesk.Revit.DB.ViewType.ProjectBrowser: case Autodesk.Revit.DB.ViewType.SystemBrowser: case Autodesk.Revit.DB.ViewType.Internal: case Autodesk.Revit.DB.ViewType.DrawingSheet: return(false); case Autodesk.Revit.DB.ViewType.FloorPlan: case Autodesk.Revit.DB.ViewType.EngineeringPlan: case Autodesk.Revit.DB.ViewType.AreaPlan: case Autodesk.Revit.DB.ViewType.CeilingPlan: case Autodesk.Revit.DB.ViewType.Elevation: case Autodesk.Revit.DB.ViewType.Section: case Autodesk.Revit.DB.ViewType.Detail: case Autodesk.Revit.DB.ViewType.ThreeD: case Autodesk.Revit.DB.ViewType.DraftingView: case Autodesk.Revit.DB.ViewType.Legend: case Autodesk.Revit.DB.ViewType.Report: case Autodesk.Revit.DB.ViewType.CostReport: case Autodesk.Revit.DB.ViewType.LoadsReport: case Autodesk.Revit.DB.ViewType.PresureLossReport: case Autodesk.Revit.DB.ViewType.Walkthrough: case Autodesk.Revit.DB.ViewType.Rendering: var sheet = new Autodesk.Revit.DB.FilteredElementCollector(doc) .OfClass(typeof(Autodesk.Revit.DB.ViewSheet)) .Cast <Autodesk.Revit.DB.ViewSheet>() .FirstOrDefault(x => x.GetAllPlacedViews().FirstOrDefault(y => y == v.Id) != null); return(sheet != null); case Autodesk.Revit.DB.ViewType.Schedule: case Autodesk.Revit.DB.ViewType.PanelSchedule: case Autodesk.Revit.DB.ViewType.ColumnSchedule: var schedule = v as Autodesk.Revit.DB.ViewSchedule; if (schedule == null) { throw new ArgumentException("Invalid View"); } var sheetSchedule = new Autodesk.Revit.DB.FilteredElementCollector(doc) .OfClass(typeof(Autodesk.Revit.DB.ScheduleSheetInstance)) .Cast <Autodesk.Revit.DB.ScheduleSheetInstance>() .FirstOrDefault(x => !x.IsTitleblockRevisionSchedule && x.ScheduleId == v.Id); return(sheetSchedule != null); default: throw new ArgumentOutOfRangeException(); } }
/// <summary> /// Exports the view to DWG with the view name as the output file name. /// </summary> /// <param name="view"></param> /// <param name="destination"></param> /// <param name="exportOptionsName"></param> /// <returns></returns> public static bool ExportDWG(Revit.Elements.Views.View view, string destination, string exportOptionsName) { var doc = DocumentManager.Instance.CurrentDBDocument; var iView = view.InternalElement as Autodesk.Revit.DB.View; doc.Export(destination, iView.ViewName, new[] { iView.Id }, DWGExportOptions.GetPredefinedOptions(doc, exportOptionsName)); return(true); }
public static bool IsHiddenOnView(Revit.Elements.Element element, Revit.Elements.Views.View view) { // Unwrap elements Autodesk.Revit.DB.Element elem = element.InternalElement; Autodesk.Revit.DB.View inputView = (Autodesk.Revit.DB.View)view.InternalElement; return(elem.IsHidden(inputView)); }
/// <summary> /// Get View Template applied to view. /// </summary> /// <param name="view">View to retrieve View Template from.</param> /// <returns name="view">View Template applied to view.</returns> /// <search>view, template</search> public static object ViewTemplate(View view) { var doc = DocumentManager.Instance.CurrentDBDocument; var v = (Autodesk.Revit.DB.View)view.InternalElement; var id = v.ViewTemplateId; return(id != Autodesk.Revit.DB.ElementId.InvalidElementId ? doc.GetElement(id).ToDSType(true) : null); }
/// <summary> /// Set unobscured in specified View /// </summary> /// <param name="rebar">Single Rebar</param> /// <param name="view">View</param> /// <param name="unobscured">Unobscured</param> public static void SetUnobscuredInView(Rebar rebar, Revit.Elements.Views.View view, bool unobscured) { Autodesk.Revit.DB.Document document = DocumentManager.Instance.CurrentDBDocument; TransactionManager.Instance.EnsureInTransaction(document); Autodesk.Revit.DB.Structure.Rebar rebarElement = (Autodesk.Revit.DB.Structure.Rebar)rebar.InternalElement; Autodesk.Revit.DB.View viewElement = (Autodesk.Revit.DB.View)view.InternalElement; rebarElement.SetUnobscuredInView(viewElement, unobscured); TransactionManager.Instance.TransactionTaskDone(); }
/// <summary> /// Rotates a view around its center point. It is equivalent to selecting the crop region and rotating it counter clockwise. /// </summary> /// <param name="view">The view to rotate.</param> /// <param name="degrees">Rotation angle in degrees. Everything visible in the view will be rotated clockwise by this amount.</param> /// <returns>The rotated view.</returns> public static Revit.Elements.Views.View Rotate(Revit.Elements.Views.View view, double degrees) { // Setup var doc = DocumentManager.Instance.CurrentDBDocument; var iView = view.InternalElement as Autodesk.Revit.DB.View; ViewCrop viewCrop = GetViewCrop(iView); // Rotate the crop element RotateCropElement(iView, viewCrop.cropElement, degrees); return(view); }
public static BoundingBox BoundingBox(Element element, View view = null) { if (element == null) { throw new ArgumentNullException(nameof(element)); } var v = view?.InternalElement as Autodesk.Revit.DB.View; var bb = element.InternalElement.get_BoundingBox(v); return(bb.ToProtoType()); }
public static bool IsVisibleInView(Element element, View view) { if (element == null) { throw new ArgumentNullException(nameof(element)); } return(FindAllViewsWhereElementIsVisible(element, new List <Autodesk.Revit.DB.View> { view.InternalElement as Autodesk.Revit.DB.View }).Any()); }
public static Dictionary <string, object> ElementTaggedStatus(Revit.Elements.Views.View view, Revit.Elements.Category category) { var viewId = view.InternalElement.Id; var categoryId = category.Id; Document doc = DocumentManager.Instance.CurrentDBDocument; BuiltInCategory myCatEnum = (BuiltInCategory)Enum.Parse(typeof(BuiltInCategory), categoryId.ToString()); List <Revit.Elements.Element> notTaggedList = new List <Revit.Elements.Element>(); foreach (Autodesk.Revit.DB.Element e in new FilteredElementCollector(doc, viewId) .OfCategory(myCatEnum).WhereElementIsNotElementType()) { if (new FilteredElementCollector(doc, viewId) .OfClass(typeof(IndependentTag)) .Cast <IndependentTag>() .FirstOrDefault(q => q.TaggedLocalElementId == e.Id) == null) { notTaggedList.Add(e.ToDSType(true)); } } List <Revit.Elements.Element> allTagged = new List <Revit.Elements.Element>(); FilteredElementCollector allInView = new FilteredElementCollector(doc, viewId) .OfClass(typeof(IndependentTag)).WhereElementIsNotElementType(); var elementCollection = allInView.ToElements(); foreach (Autodesk.Revit.DB.Element t in elementCollection) { var tag = (Tag)t.ToDSType(true); allTagged.Add(tag.TaggedElement); } List <Revit.Elements.Element> taggedList = new List <Revit.Elements.Element>(); foreach (Element element in allTagged) { if (element.InternalElement.Category.Id.ToString() == category.Id.ToString()) { taggedList.Add(element.InternalElement.ToDSType(true)); } } //returns the outputs var outInfo = new Dictionary <string, object> { { "notTagged", notTaggedList }, { "tagged", taggedList } }; return(outInfo); }
/// <summary> /// Retrieves Crop Box of the View as Bounding Box object. /// </summary> /// <param name="view">View to extract the Crop Box from.</param> /// <returns name="boundingBox">Bounding Box.</returns> /// <search>view, crop box</search> public static BoundingBox CropBox(View view) { if (!(view.InternalElement is Autodesk.Revit.DB.View v)) { throw new ArgumentNullException(nameof(view)); } var cb = v.CropBox; var min = cb.Min.ToPoint(); var max = cb.Max.ToPoint(); return(BoundingBox.ByCorners(min, max)); }
/// <summary> /// Get the rotation of the crop element of a view. The rotation is expressed in degrees, counter clockwise. /// </summary> /// <param name="view"></param> /// <returns></returns> public static double GetRotation(Revit.Elements.Views.View view) { XYZ rightDirection = (view.InternalElement as Autodesk.Revit.DB.View).RightDirection; int sign = 1; if (rightDirection.Y < 0) { sign = -1; } return(rightDirection.AngleTo(XYZ.BasisX) * 180.0 / Math.PI * sign); }
/// <summary> /// Construct a Revit Dimension from at least two elements /// </summary> /// <param name="view">View to place dimension in</param> /// <param name="referenceElements">Elements to dimension</param> /// <param name="line">location of the dimension</param> /// <param name="suffix">Suffix</param> /// <param name="prefix">Prefix</param> /// <returns>Dimension</returns> public static Dimension ByElements(Revit.Elements.Views.View view, IEnumerable <Revit.Elements.Element> referenceElements, [DefaultArgument("null")] Autodesk.DesignScript.Geometry.Line line, string suffix = "", string prefix = "") { var elements = referenceElements.ToList(); if (elements.Count < 2) { throw new Exception(Properties.Resources.NotEnoughDataError); } Autodesk.Revit.DB.View revitView = (Autodesk.Revit.DB.View)view.InternalElement; Line revitLine = null; // if there is no location line supplied, draw a line between the midpoints // of the supplied elements. if (line == null) { BoundingBoxXYZ boundingBoxFirstElement = elements[0].InternalElement.get_BoundingBox(revitView); if ((boundingBoxFirstElement) == null) { throw new Exception(Properties.Resources.ElementCannotBeAnnotatedError); } BoundingBoxXYZ boundingBoxLastElement = elements[elements.Count - 1].InternalElement.get_BoundingBox(revitView); if ((boundingBoxLastElement) == null) { throw new Exception(Properties.Resources.ElementCannotBeAnnotatedError); } revitLine = Line.CreateBound(GetMidpoint(boundingBoxFirstElement), GetMidpoint(boundingBoxLastElement)); } else { revitLine = (Line)line.ToRevitType(true); } if (!view.IsAnnotationView()) { throw new Exception(Properties.Resources.ViewDoesNotSupportAnnotations); } ReferenceArray array = new ReferenceArray(); foreach (Revit.Elements.Element element in elements) { array.Append(new Reference(element.InternalElement)); } return(new Dimension(revitView, revitLine, array, suffix, prefix)); }
/// <summary> /// Set unobscured in specified View /// </summary> /// <param name="rebarContainer">Rebar Container</param> /// <param name="view">View</param> /// <param name="unobscured">Unobscured</param> public static void SetUnobscuredInView(Element rebarContainer, Revit.Elements.Views.View view, bool unobscured) { Autodesk.Revit.DB.Structure.RebarContainer bar = rebarContainer.InternalElement as Autodesk.Revit.DB.Structure.RebarContainer; if (bar != null) { Autodesk.Revit.DB.Document document = DocumentManager.Instance.CurrentDBDocument; TransactionManager.Instance.EnsureInTransaction(document); Autodesk.Revit.DB.View viewElement = (Autodesk.Revit.DB.View)view.InternalElement; bar.SetUnobscuredInView(viewElement, unobscured); TransactionManager.Instance.TransactionTaskDone(); } }
/// <summary> /// Set Bar hidden Status /// </summary> /// <param name="rebar">Rebar element</param> /// <param name="view">Revit View</param> /// <param name="barIndex">Bar Index</param> /// <param name="hidden">Hidden Status</param> public static void SetBarHiddenStatus(Revit.Elements.Element rebar, Revit.Elements.Views.View view, int barIndex, bool hidden) { Autodesk.Revit.DB.Structure.Rebar bar = rebar.InternalElement as Autodesk.Revit.DB.Structure.Rebar; if (bar != null) { Autodesk.Revit.DB.Document document = DocumentManager.Instance.CurrentDBDocument; TransactionManager.Instance.EnsureInTransaction(document); Autodesk.Revit.DB.View viewElement = (Autodesk.Revit.DB.View)view.InternalElement; bar.SetBarHiddenStatus(viewElement, barIndex, hidden); TransactionManager.Instance.TransactionTaskDone(); } }
/// <summary> /// Duplicates an existing view. /// </summary> /// <param name="view">View to duplicate.</param> /// <param name="name">Name to be assigned to new view.</param> /// <param name="options">Duplicate options. Ex: Duplicate as Dependent.</param> /// <returns name="view">New View.</returns> /// <search>view, duplicate</search> public static View Duplicate(View view, string name, string options) { var doc = DocumentManager.Instance.CurrentDBDocument; var v = (Autodesk.Revit.DB.View)view.InternalElement; var dupOptions = (Autodesk.Revit.DB.ViewDuplicateOption)Enum.Parse(typeof(Autodesk.Revit.DB.ViewDuplicateOption), options); TransactionManager.Instance.EnsureInTransaction(doc); var newView = doc.GetElement(v.Duplicate(dupOptions)); newView.Name = name; TransactionManager.Instance.TransactionTaskDone(); return(newView.ToDSType(true) as View); }
/// <summary> /// Create a Revit Tag for a Revit Element at a specified location point /// </summary> /// <param name="view">View to tag in</param> /// <param name="element">Element to tag</param> /// <param name="location">Location point</param> /// <param name="horizontal">Optional: Place tag horizontal, defaults to true</param> /// <param name="addLeader">Optional: Add a leader, defaults to false</param> /// <returns></returns> /// <search> /// tagelement,annotate,documentation,taglocation /// </search> public static Tag ByElementAndLocation(Revit.Elements.Views.View view, Element element, Autodesk.DesignScript.Geometry.Point location, bool horizontal = true, bool addLeader = false) { Autodesk.Revit.DB.View revitView = (Autodesk.Revit.DB.View)view.InternalElement; Autodesk.Revit.DB.XYZ point = location.ToRevitType(true); Autodesk.Revit.DB.TagMode tagMode = TagMode.TM_ADDBY_CATEGORY; Autodesk.Revit.DB.TagOrientation orientation = (horizontal) ? TagOrientation.Horizontal : TagOrientation.Vertical; if (!view.IsAnnotationView()) { throw new Exception(Properties.Resources.ViewDoesNotSupportAnnotations); } return(new Tag(revitView, element.InternalElement, orientation, tagMode, addLeader, point)); }
/// <summary> /// Sets Workset visibility for a View. /// </summary> /// <param name="view">View to set the visibility on.</param> /// <param name="worksets">Worksets to set the visibility for.</param> /// <param name="visibility">Visibility setting. Ex: Hide.</param> /// <returns name="view">View</returns> /// <search>workset, visibility, set</search> public static View SetWorksetVisibility(View view, List <Workset> worksets, string visibility) { var doc = DocumentManager.Instance.CurrentDBDocument; var v = (Autodesk.Revit.DB.View)view.InternalElement; var vis = (Autodesk.Revit.DB.WorksetVisibility)Enum.Parse(typeof(Autodesk.Revit.DB.WorksetVisibility), visibility); TransactionManager.Instance.EnsureInTransaction(doc); foreach (var w in worksets) { v.SetWorksetVisibility(w.InternalWorkset.Id, vis); } TransactionManager.Instance.TransactionTaskDone(); return(view); }
/// <summary> /// Retrieves Reference Callouts from a View. /// </summary> /// <param name="view">View to retrieve Reference Callouts from.</param> /// <returns name="callout[]">List of Reference Callouts.</returns> /// <search>get, reference, callout</search> public static List <Element> GetReferenceCallouts(View view) { if (view == null) { throw new ArgumentNullException(nameof(view)); } if (!(view.InternalElement is Autodesk.Revit.DB.View v)) { throw new ArgumentException("View is not a valid type."); } var doc = DocumentManager.Instance.CurrentDBDocument; return(v.GetReferenceCallouts().Select(x => doc.GetElement(x).ToDSType(true)).ToList()); }
/// <summary> /// Construct a Revit Linear Dimension from at least two Edges. /// </summary> /// <param name="view">View to place dimension in</param> /// <param name="referenceCurves">Edges to dimension</param> /// <param name="line">location of the dimension</param> /// <param name="suffix">Suffix</param> /// <param name="prefix">Prefix</param> /// <returns></returns> public static Dimension ByEdges(Revit.Elements.Views.View view, IEnumerable <Autodesk.DesignScript.Geometry.Curve> referenceCurves, [DefaultArgument("null")] Autodesk.DesignScript.Geometry.Line line, string suffix = "", string prefix = "") { var curves = referenceCurves.ToList(); if (curves.Count < 2) { throw new Exception(string.Format(Properties.Resources.NotEnoughDataError, "Curves")); } Autodesk.Revit.DB.View revitView = (Autodesk.Revit.DB.View)view.InternalElement; Line revitLine = null; if (!view.IsAnnotationView()) { throw new Exception(Properties.Resources.ViewDoesNotSupportAnnotations); } if (line == null) { BoundingBoxXYZ boundingBoxFirstElement = curves[0].BoundingBox.ToRevitType(); if ((boundingBoxFirstElement) == null) { throw new Exception(Properties.Resources.ElementCannotBeAnnotatedError); } BoundingBoxXYZ boundingBoxLastElement = curves[curves.Count - 1].BoundingBox.ToRevitType(); if ((boundingBoxLastElement) == null) { throw new Exception(Properties.Resources.ElementCannotBeAnnotatedError); } revitLine = Line.CreateBound(GetMidpoint(boundingBoxFirstElement), GetMidpoint(boundingBoxLastElement)); } else { revitLine = (Line)line.ToRevitType(true); } ReferenceArray array = new ReferenceArray(); foreach (var curve in curves) { var reference = Revit.GeometryReferences.ElementCurveReference.TryGetCurveReference(curve); array.Append(reference.InternalReference); } return(new Dimension(revitView, revitLine, array, suffix, prefix)); }
/// <summary> /// Create a Dimension for an Element in the specified direction and view. /// </summary> /// <param name="view">View to place dimension in</param> /// <param name="element">The element of generated Dimension</param> /// <param name="direction">The direction to create Dimension</param> /// <param name="line">location of the dimension</param> /// <param name="suffix">Suffix</param> /// <param name="prefix">Prefix</param> /// <returns></returns> public static Dimension ByElementDirection(Revit.Elements.Views.View view, Revit.Elements.Element element, Autodesk.DesignScript.Geometry.Vector direction, [DefaultArgument("null")] Autodesk.DesignScript.Geometry.Line line, string suffix = "", string prefix = "") { Autodesk.Revit.DB.View revitView = (Autodesk.Revit.DB.View)view.InternalElement; if (!view.IsAnnotationView()) { throw new Exception(Properties.Resources.ViewDoesNotSupportAnnotations); } var revitDirection = direction.ToRevitType(); List <Autodesk.Revit.DB.PlanarFace> planars = new List <PlanarFace>(); ReferenceArray array = new ReferenceArray(); var opt = new Options(); opt.ComputeReferences = true; var faces = element.InternalGeometry(false).OfType <Autodesk.Revit.DB.Solid>().SelectMany(x => x.Faces.OfType <Autodesk.Revit.DB.PlanarFace>()); var references = faces.Select(x => x.Reference); Line revitLine = null; foreach (var face in faces) { var isParallel = direction.IsParallel(face.FaceNormal.ToVector()); if (isParallel) { array.Append(face.Reference); planars.Add(face); } } if (planars.Count < 2) { throw new Exception(string.Format(Properties.Resources.NotEnoughDataError, "Surface on this Direction")); } if (line == null) { revitLine = Line.CreateBound(planars[0].Origin, planars[0].Origin.Add(direction.ToXyz())); } else { revitLine = (Line)line.ToRevitType(true); } return(new Dimension(revitView, revitLine, array, suffix, prefix)); }
/// <summary> /// Show a colored Point Analysis Display in the Revit view. /// </summary> /// <param name="view">The view into which you want to draw the analysis results.</param> /// <param name="data">A list of PointAnalysisData objects.</param> /// <param name="name">An optional analysis results name to show on the results legend.</param> /// <param name="description">An optional analysis results description to show on the results legend.</param> /// <param name="unitType">An optional Unit type to provide conversions in the analysis results.</param> /// <returns>An PointAnalysisDisplay object.</returns> public static PointAnalysisDisplay ByViewAndPointAnalysisData(View view, PointAnalysisData[] data, string name = "", string description = "", Type unitType = null) { if (view == null) { throw new ArgumentNullException("view"); } if (data == null) { throw new ArgumentNullException("data"); } if (!data.Any()) { throw new Exception("There is no input data."); } if (string.IsNullOrEmpty(name)) { name = Resource1.AnalysisResultsDefaultName; } if (string.IsNullOrEmpty(description)) { description = Resource1.AnalysisResultsDefaultDescription; } return new PointAnalysisDisplay(view.InternalView, data, name, description, unitType); }
/// <summary> /// Show a colored Point Analysis Display in the Revit view. /// </summary> /// <param name="view">The view into which you want to draw the analysis results.</param> /// <param name="sampleLocations">The locations at which you want to create analysis values.</param> /// <param name="samples">The analysis values at the given locations.</param> /// <param name="name">An optional analysis results name to show on the results legend.</param> /// <param name="description">An optional analysis results description to show on the results legend.</param> /// <param name="unitType">An optional Unit type to provide conversions in the analysis results.</param> /// <returns>An PointAnalysisDisplay object.</returns> public static PointAnalysisDisplay ByViewPointsAndValues(View view, Autodesk.DesignScript.Geometry.Point[] sampleLocations, double[] samples, string name = "", string description = "", Type unitType = null) { if (view == null) { throw new ArgumentNullException("view"); } if (sampleLocations == null) { throw new ArgumentNullException("samplePoints"); } if (samples == null) { throw new ArgumentNullException("samples"); } if (sampleLocations.Length != samples.Length) { throw new Exception("The number of sample points and number of samples must be the same"); } if (string.IsNullOrEmpty(name)) { name = Resource1.AnalysisResultsDefaultName; } if (string.IsNullOrEmpty(description)) { description = Resource1.AnalysisResultsDefaultDescription; } var data = PointAnalysisData.ByPointsAndResults (sampleLocations, new List<string>{"Dynamo Data"}, new List<IList<double>>{samples}); return new PointAnalysisDisplay(view.InternalView, new List<PointAnalysisData> { data }, name, description, unitType); }