/// <summary> /// Set Horizontal Text Alignment /// </summary> /// <param name="value"></param> public void SetHorizontalAlignment(string value) { if (value != HorizontalAlignment) { RVT.HorizontalTextAlignment alignment = HorizontalTextAlignment.Left; Enum.TryParse <RVT.HorizontalTextAlignment>(value, out alignment); TransactionManager.Instance.EnsureInTransaction(Application.Document.Current.InternalDocument); this.InternalTextNote.HorizontalAlignment = alignment; TransactionManager.Instance.TransactionTaskDone(); } }
/// <summary> /// Construct a new Revit TextNote by Location /// </summary> /// <param name="view">View to place text element on</param> /// <param name="location">Location in view</param> /// <param name="text">Text</param> /// <param name="alignment">Text alignment</param> /// <param name="keepRotatedTextReadable">Keep text horizontal</param> /// <param name="rotation">Rotation in degrees</param> /// <param name="type">Revit TextNote Type</param> /// <returns></returns> public static TextNote ByLocation(Revit.Elements.Views.View view, Autodesk.DesignScript.Geometry.Point location, string text, string alignment, [DefaultArgument("Revit.Elements.TextNoteType.Default()")] TextNoteType type, bool keepRotatedTextReadable = true, double rotation = 0) { RVT.HorizontalTextAlignment horizontalTextAlignmentStyle = HorizontalTextAlignment.Center; if (!Enum.TryParse <RVT.HorizontalTextAlignment>(alignment, out horizontalTextAlignmentStyle)) { horizontalTextAlignmentStyle = HorizontalTextAlignment.Center; } Autodesk.Revit.DB.View revitView = (Autodesk.Revit.DB.View)view.InternalElement; if (!view.IsAnnotationView()) { throw new Exception(Properties.Resources.ViewDoesNotSupportAnnotations); } return(new TextNote(revitView, location.ToRevitType(true), horizontalTextAlignmentStyle, text, keepRotatedTextReadable, rotation, type.InternalElement.Id)); }
/// <summary> /// TextNote by Location /// </summary> /// <param name="view"></param> /// <param name="origin"></param> /// <param name="alignment"></param> /// <param name="text"></param> /// <param name="keepRotatedTextreadable"></param> /// <param name="rotation">in degrees</param> /// <param name="typeId"></param> private TextNote(RVT.View view, RVT.XYZ origin, RVT.HorizontalTextAlignment alignment, string text, bool keepRotatedTextreadable, double rotation, ElementId typeId) { SafeInit(() => Init(view, origin, alignment, text, keepRotatedTextreadable, rotation, typeId)); }
/// <summary> /// Init element by location /// </summary> /// <param name="view"></param> /// <param name="origin"></param> /// <param name="alignment"></param> /// <param name="text"></param> /// <param name="keepRotatedTextreadable"></param> /// <param name="rotation">in degrees</param> /// <param name="typeId"></param> private void Init(RVT.View view, RVT.XYZ origin, RVT.HorizontalTextAlignment alignment, string text, bool keepRotatedTextreadable, double rotation, ElementId typeId) { Autodesk.Revit.DB.Document document = DocumentManager.Instance.CurrentDBDocument; TransactionManager.Instance.EnsureInTransaction(document); var element = ElementBinder.GetElementFromTrace <RVT.TextNote>(document); RVT.TextNoteOptions options = new TextNoteOptions() { HorizontalAlignment = alignment, KeepRotatedTextReadable = keepRotatedTextreadable, Rotation = rotation.ToRadians(), TypeId = typeId }; if (element == null) { element = RVT.TextNote.Create(document, view.Id, origin, text, options); } else { if (element.HorizontalAlignment != alignment) { element.HorizontalAlignment = alignment; } if (element.KeepRotatedTextReadable != keepRotatedTextreadable) { element.KeepRotatedTextReadable = keepRotatedTextreadable; } if (element.Text != text) { element.Text = text; } // if the element location is null, try to use the Coord property // Coord holds a point only without rotation. if (element.Location == null) { if (!element.Coord.IsAlmostEqualTo(origin)) { element.Coord = origin; } } else { // If a location point is set we can use this and extract // its location and rotation if (element.Location is LocationPoint) { LocationPoint point = (LocationPoint)element.Location; if (!point.Point.IsAlmostEqualTo(origin)) { point.Point = origin; } if (Math.Abs(point.Rotation - rotation.ToRadians()) <= System.Double.Epsilon) { point.Rotate(Line.CreateUnbound(XYZ.Zero, XYZ.BasisZ), rotation.ToRadians()); } } } } RVT.TextNoteType type = (RVT.TextNoteType)document.GetElement(typeId); InternalSetType(text, type, origin, alignment, rotation); InternalSetElement(element); TransactionManager.Instance.TransactionTaskDone(); ElementBinder.SetElementForTrace(this.InternalElement); }