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时,要注意考虑缩放系数
*/
///
/// 视图中的文字
///
///
///
public static List GetTextNotes(this View view)
{
return null;// view.GetViewElements(ElementFilters.TextNote).ToListExt();
}
///
/// 项目中的文字
///
///
///
public static List GetTextNotes(this Document doc)
{
return doc.GetElements();
}
///
/// 获取项目中NoteType全集
///
///
///
public static List GetTextNoteTypes(this Document doc)
{
return doc.GetElements();
}
///
/// 获取系统默认使用NodtType
///
///
///
public static TextNoteType GetDefaultNodeType(this Document doc)
{
return doc.GetTextNodeType("仿宋", 3, 0.7);
}
///
/// 获取TextNodeType
///
///
///
///
///
///
public static TextNoteType GetTextNodeType(this Document doc, string font, double fontHeight,
double widthRatio)
{
List 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(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;
}
///
/// 试图创建新的TextNode
///
///
///
///
///
///
///
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);
}
///
/// 试图创建新的TextNode
///
///
///
///
///
///
///
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;
}
}
}