/// <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)); }
/// <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> /// Create a Revit Tag for a Revit Element /// </summary> /// <param name="view">View to Tag</param> /// <param name="element">Element to tag</param> /// <param name="horizontal">Horizontal alignment</param> /// <param name="addLeader">Add a leader</param> /// <param name="offset">Offset Vector or Tag Location</param> /// <param name="isOffset">Specifies if the point is being used as an offset vector or if it specifies the tags location</param> /// <param name="horizontalAlignment">Horizontal Alignment</param> /// <param name="verticalAlignment">Vertical Alignment</param> /// <returns></returns> public static Tag ByElement(Revit.Elements.Views.View view, Element element, bool horizontal, bool addLeader, string horizontalAlignment, string verticalAlignment, [DefaultArgument("Autodesk.DesignScript.Geometry.Vector.ByCoordinates(0,0,0)")] Autodesk.DesignScript.Geometry.Vector offset, bool isOffset = true) { 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; Autodesk.Revit.DB.XYZ point = offset.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); } if (isOffset) { BoundingBoxXYZ box = element.InternalElement.get_BoundingBox(revitView); if (box == null) { box = element.InternalElement.get_BoundingBox(null); } if (box != null) { double Y, X = 0; switch (verticalAlignmentStyle) { case VerticalAlignmentStyle.Bottom: Y = box.Min.Y; break; case VerticalAlignmentStyle.Top: Y = box.Max.Y; break; default: Y = box.Min.Y + ((box.Max.Y - box.Min.Y) / 2); break; } switch (horizontalAlignmentStyle) { case HorizontalAlignmentStyle.Left: X = box.Min.X; break; case HorizontalAlignmentStyle.Right: X = box.Max.X; break; default: X = box.Min.X + ((box.Max.X - box.Min.X) / 2); break; } point = new XYZ(X + point.X, Y + point.Y, 0 + point.Z); } else { if (element.InternalElement.Location != null) { if (element.InternalElement.Location.GetType() == typeof(LocationCurve)) { LocationCurve lc = (LocationCurve)element.InternalElement.Location; XYZ midpoint = lc.Curve.Evaluate(0.5, true); point = new XYZ(midpoint.X + point.X, midpoint.Y + point.Y, 0 + point.Z); } else if (element.InternalElement.Location.GetType() == typeof(LocationPoint)) { LocationPoint lp = (LocationPoint)element.InternalElement.Location; point = new XYZ(lp.Point.X + point.X, lp.Point.Y + point.Y, 0 + point.Z); } else { throw new Exception(Properties.Resources.InvalidElementLocation); } } else { throw new Exception(Properties.Resources.InvalidElementLocation); } } } return(new Tag(revitView, element.InternalElement, orientation, tagMode, addLeader, point)); }
/// <summary> /// Create Rebar by Curves /// </summary> /// <param name="curve">Input Curves</param> /// <param name="hostElementId">Host Element Id</param> /// <param name="rebarStyle">Rebar Style</param> /// <param name="rebarBarType">Bar Type</param> /// <param name="startHookOrientation">Hokk orientation at the start</param> /// <param name="endHookOrientation">Hook orientation at the end</param> /// <param name="startHookType">Hook type at the start</param> /// <param name="endHookType">Hook type at the end</param> /// <param name="vector">Normal Vectors</param> /// <returns></returns> public static Rebar ByCurve( Autodesk.DesignScript.Geometry.Curve curve, int hostElementId, string rebarStyle, Revit.Elements.Element rebarBarType, string startHookOrientation, string endHookOrientation, Revit.Elements.Element startHookType, Revit.Elements.Element endHookType, Autodesk.DesignScript.Geometry.Vector vector ) { if (curve == null) { throw new ArgumentNullException("Input Curve missing"); } if (hostElementId == null) { throw new ArgumentNullException("Host ElementId missing"); } if (rebarStyle == null) { throw new ArgumentNullException("Rebar Style missing"); } if (rebarBarType == null) { throw new ArgumentNullException("Rebar Bar Type missing"); } if (startHookOrientation == null) { throw new ArgumentNullException("Start Hook Orientation missing"); } if (endHookOrientation == null) { throw new ArgumentNullException("End Hook Orientation missing"); } //if (startHookType == null) throw new ArgumentNullException("Start Hook Type missing"); //if (endHookType == null) throw new ArgumentNullException("End Hook Type missing"); if (vector == null) { throw new ArgumentNullException("Normal Vector missing"); } ElementId elementId = new ElementId(hostElementId); if (elementId == ElementId.InvalidElementId) { throw new ArgumentNullException("Host ElementId error"); } Autodesk.Revit.DB.Element host = DocumentManager.Instance.CurrentDBDocument.GetElement(elementId); Autodesk.Revit.DB.Structure.RebarStyle barStyle = Autodesk.Revit.DB.Structure.RebarStyle.StirrupTie; Enum.TryParse <Autodesk.Revit.DB.Structure.RebarStyle>(rebarStyle, out barStyle); Autodesk.Revit.DB.Structure.RebarHookOrientation startOrientation = Autodesk.Revit.DB.Structure.RebarHookOrientation.Left; Enum.TryParse <Autodesk.Revit.DB.Structure.RebarHookOrientation>(startHookOrientation, out startOrientation); Autodesk.Revit.DB.Structure.RebarHookOrientation endOrientation = Autodesk.Revit.DB.Structure.RebarHookOrientation.Left; Enum.TryParse <Autodesk.Revit.DB.Structure.RebarHookOrientation>(endHookOrientation, out endOrientation); Autodesk.Revit.DB.Structure.RebarHookType startHookT = (startHookType == null) ? null : (Autodesk.Revit.DB.Structure.RebarHookType)startHookType.InternalElement; Autodesk.Revit.DB.Structure.RebarHookType endHookT = (endHookType == null) ? null : (Autodesk.Revit.DB.Structure.RebarHookType)endHookType.InternalElement; return(new Rebar(curve.ApproximateToRvt(), (Autodesk.Revit.DB.Structure.RebarBarType)rebarBarType.InternalElement, barStyle, host, startHookT, endHookT , startOrientation, endOrientation, vector.ToRevitType(), true, true)); }