123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- using Autodesk.Revit.DB;
- using FWindSoft.Revit.Common;
- using FWindSoft.SystemExtensions;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace FWindSoft.Revit
- {
- public static class TextNodeExtension
- {
- /*
- * 操作TextNode时,要注意考虑缩放系数
- */
- /// <summary>
- /// 视图中的文字
- /// </summary>
- /// <param name="view"></param>
- /// <returns></returns>
- public static List<TextNote> GetTextNotes(this View view)
- {
- return null;// view.GetViewElements(ElementFilters.TextNote).ToListExt<TextNote>();
- }
- /// <summary>
- /// 项目中的文字
- /// </summary>
- /// <param name="doc"></param>
- /// <returns></returns>
- public static List<TextNote> GetTextNotes(this Document doc)
- {
- return doc.GetElements<TextNote>();
- }
- /// <summary>
- /// 获取项目中NoteType全集
- /// </summary>
- /// <param name="doc"></param>
- /// <returns></returns>
- public static List<TextNoteType> GetTextNoteTypes(this Document doc)
- {
- return doc.GetElements<TextNoteType>();
- }
- /// <summary>
- /// 获取系统默认使用NodtType
- /// </summary>
- /// <param name="doc"></param>
- /// <returns></returns>
- public static TextNoteType GetDefaultNodeType(this Document doc)
- {
- return doc.GetTextNodeType("仿宋", 3, 0.7);
- }
- /// <summary>
- /// 获取TextNodeType
- /// </summary>
- /// <param name="doc"></param>
- /// <param name="font"></param>
- /// <param name="fontHeight"></param>
- /// <param name="widthRatio"></param>
- /// <returns></returns>
- public static TextNoteType GetTextNodeType(this Document doc, string font, double fontHeight,
- double widthRatio)
- {
- List<TextNoteType> types = doc.GetTextNoteTypes();
- TextNoteType useType = null;
- var typeName = string.Format("{0} {1}*{2}", font, fontHeight, widthRatio );
- if (types.Count > 0)
- {
- typeName = RevitTools.RemoveForbiddenChars(typeName);
- useType = types.FirstOrDefault(t => t.Name == typeName);
- if (useType == null)
- {
- useType = types[0].DuplicateT<TextNoteType>(typeName);
- useType.SetParameter(BuiltInParameter.TEXT_WIDTH_SCALE, widthRatio);
- useType.SetParameter(BuiltInParameter.TEXT_SIZE, fontHeight.MmToFt());
- useType.SetParameter(BuiltInParameter.TEXT_FONT, font);
- useType.SetParameter(BuiltInParameter.TEXT_BACKGROUND, 1);
- useType.SetParameter(BuiltInParameter.LEADER_OFFSET_SHEET, 0.0);
- }
- }
- return useType;
- }
-
- /// <summary>
- /// 试图创建新的TextNode
- /// </summary>
- /// <param name="view"></param>
- /// <param name="typeId"></param>
- /// <param name="position"></param>
- /// <param name="text"></param>
- /// <param name="angle"></param>
- /// <returns></returns>
- public static TextNote NewTextNote(this View view, ElementId typeId, XYZ position, string text,
- double angle = 0)
- {
- TextNoteOptions options = new TextNoteOptions
- {
- TypeId = typeId,
- Rotation = angle
- };
- return TextNote.Create(view.Document, view.Id, position, text, options);
- }
- /// <summary>
- /// 试图创建新的TextNode
- /// </summary>
- /// <param name="view"></param>
- /// <param name="typeId"></param>
- /// <param name="position"></param>
- /// <param name="text"></param>
- /// <param name="angle"></param>
- /// <returns></returns>
- public static TextNote NewTextNote(this View view, ElementId typeId, XYZ position, string text, double width,
- TextAlignFlags textAlign,double angle = 0)
- {
- TextNoteOptions options = new TextNoteOptions
- {
- TypeId = typeId,
- Rotation = angle
- };
- TextNote note;
- if (width.IsZero())
- {
- note = TextNote.Create(view.Document, view.Id, position, text, options);
- }
- else
- {
- note = TextNote.Create(view.Document, view.Id, position, width, text, options);
- }
- note?.SetParameter(BuiltInParameter.TEXT_ALIGN_HORZ, (int)textAlign);
- return note;
- }
- }
- }
|