Autodesk.Revit.DB.FormattedText是Revit API中的一个类,它表示带有格式的文本,可以用于Revit图形用户界面(GUI)中的文本标签和注释等场景。
public FormattedText(string text):创建一个新的FormattedText对象,其中包含给定的文本text。public string Text { get; }:获取文本内容。public Font Font { get; set; }:获取或设置字体。public Color Color { get; set; }:获取或设置颜色。public TextDecoration Decoration { get; set; }:获取或设置文本修饰。FormattedText类内部定义了以下常量:
public static readonly FormattedText Default:默认的格式化文本,即不带任何样式和修饰的文本。// 创建格式化文本对象
FormattedText formattedText = new FormattedText("Hello World!");
formattedText.Font = new Font("Arial", 10);
formattedText.Color = Color.Red;
formattedText.Decoration = TextDecoration.Underline;
// 将格式化文本应用于Revit标签
Tag tag = new FilteredElementCollector(doc)
.OfCategory(BuiltInCategory.OST_Walls)
.WhereElementIsNotElementType()
.First() as Tag;
if (tag != null)
{
tag.TagText = formattedText;
}
FormattedText类用于标签和注释等场景,不适用于在Revit视图中显示文本,要在Revit视图中显示文本,请参见Autodesk.Revit.DB.TextNote类。FormattedText类只能表示单行文本,无法表示多行文本,若需表示多行文本,请使用Autodesk.Revit.DB.MultilineText类。