Revit二開之創建TextNote
TextNode在Revit注釋模塊中,具體位置如圖所示
圖中是Revit2018版本
【Revit中的使用】
Revit 中的操作是點擊上圖中的按鈕在平面視圖中點擊任意放置放置就行,
在屬性中可以修改文字
代碼實現
創建TextNode
ExternalCommandData externalCommandData = CommandData as ExternalCommandData;
UIDocument uiDoc = externalCommandData.Application.ActiveUIDocument;
Document rvtDoc = uiDoc.Document;
// 獲取當前活動的文檔
View activeView = uiDoc.ActiveView;
XYZ textOrigion = new XYZ(10, 10, 0);
ElementId textdefaultTypeId = rvtDoc.GetDefaultElementTypeId(ElementTypeGroup.TextNoteType);
TextNote note = TextNote.Create(rvtDoc, activeView.Id, textOrigion, "這是文本內容", textdefaultTypeId);
獲取指定的TextNodeType及創建TextNodeType
下例子中獲取的是文字大小是2.5mm的TextNodeType
FilteredElementCollector textTypeFilter = new FilteredElementCollector(rvtDoc);
List<TextNoteType> textNoteTypes = textTypeFilter.OfClass(typeof(TextNoteType)).WhereElementIsElementType().Cast<TextNoteType>().ToList();TextNoteType textNoteType = textNoteTypes.Find(f =>
{Parameter parameter = f.get_Parameter(BuiltInParameter.TEXT_SIZE);if (parameter != null){double textSize = parameter.AsDouble();return Math.Abs(2.5 - textSize) < 0.0001;}return false;
});
//如果不存在則創建文字大小為2.5mm的字體
if (textNoteType==null)
{TextNoteType tmpType = textNoteTypes.First();textNoteType = tmpType.Duplicate("2.5mm") as TextNoteType;Parameter parameter = textNoteType.get_Parameter(BuiltInParameter.TEXT_SIZE);double size = UnitUtils.ConvertToInternalUnits(2.5,DisplayUnitType.DUT_MILLIMETERS);parameter.Set(size);rvtDoc.Regenerate();
}