Message 1 of 2
underline The TextNote retrieve the length of IndependentTag.text
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello Everybody:
I got a question about tag my Pipe and draw a detail line under it,but I can not retrieve the Text Length ,If I compute the text bytelength, the length differs when the font changes.I got an method to compute the length via create a TextNote and retrieve the textnote width, it works fine In Revit Above Revit 2016,but in Revit 2014 and 2015,the TextNote is old doc.create.NewTextNote,and I always get the same width , in another word,It does'nt act well as In Revit 2016. So How can I get the length In Revit 2014 and 2015?
Below is my code.
thanks!
Snippet
public static TextNote CreateTextNote(Document doc,ElementId viewId,XYZ origin,string str,ElementId noteTypeId) { #if REVIT2014 || REVIT2015 View pview = doc.GetElement(viewId) as View; XYZ baseVec = pview.RightDirection; XYZ upVec = pview.ViewDirection; return doc.Create.NewTextNote(pview, origin, baseVec, upVec,0,TextAlignFlags.TEF_ALIGN_LEFT, str); #else return TextNote.Create(doc, viewId, origin, str, noteTypeId);#endif }
Snippet
private double getTextLength(Document doc, TETInfoCollect tet, string str, Autodesk.Revit.DB.View tagView) { //Try to get View named "Level 1" where the TextNotes are Autodesk.Revit.DB.View view = (from elem in new FilteredElementCollector(doc).OfClass(typeof(ViewPlan)).ToElements() let var = elem as Autodesk.Revit.DB.View where var != null && !var.IsTemplate && null != var.Name && ViewType.FloorPlan == var.ViewType select var).First(); double res = 0.0; //Try to get View named "Level 1" where the TextNotes are Autodesk.Revit.DB.TextNoteType noteType = (from elem in new FilteredElementCollector(doc).OfClass(typeof(TextNoteType)).ToElements() let var = elem as Autodesk.Revit.DB.TextNoteType where var != null && null != var.Name select var).First(); SubTransaction subTr = new SubTransaction(doc); subTr.Start(); Autodesk.Revit.DB.XYZ origin = new Autodesk.Revit.DB.XYZ(0, -100, 0); //Autodesk.Revit.DB.XYZ baseVec = new Autodesk.Revit.DB.XYZ(1, 0, 0); //Autodesk.Revit.DB.XYZ upVec = new Autodesk.Revit.DB.XYZ(0, 0, 1); //TextNote tnTemp = doc.Create.NewTextNote(view, origin, baseVec, upVec, 1, TextAlignFlags.TEF_ALIGN_LEFT , str); TextNote tnTemp = FuncAdapter.CreateTextNote(doc, view.Id, origin, str, noteType.Id); // Create a duplicate Element ele = noteType.Duplicate("GLS_JustForTempUse"); TextNoteType noteTypeUse = ele as TextNoteType; if (null != noteTypeUse) { noteTypeUse.get_Parameter(BuiltInParameter.TEXT_WIDTH_SCALE).Set(tet.widthScale);//宽度系数 noteTypeUse.get_Parameter(BuiltInParameter.TEXT_SIZE).Set(tet.wzSize);//文字大小 noteTypeUse.get_Parameter(BuiltInParameter.TEXT_FONT).Set(tet.wzFont);//文字字体 noteTypeUse.get_Parameter(BuiltInParameter.LINE_PEN).Set(tet.xianKuan);//线宽 noteTypeUse.get_Parameter(BuiltInParameter.LEADER_OFFSET_SHEET).Set(tet.yinxianbian);//引线边界偏移量 noteTypeUse.get_Parameter(BuiltInParameter.TEXT_TAB_SIZE).Set(tet.Biaoqianchi);//标签尺寸 noteTypeUse.get_Parameter(BuiltInParameter.TEXT_STYLE_BOLD).Set(tet.cuTi);//是否粗体 noteTypeUse.get_Parameter(BuiltInParameter.TEXT_STYLE_ITALIC).Set(tet.xieTi);//是否斜体 tnTemp.ChangeTypeId(noteTypeUse.Id); doc.Regenerate(); res = tnTemp.Width; } subTr.RollBack(); return res; }