MText使用起来是有点复杂,特别是格式的解析
下面是个生成堆叠的示例,也许有必要写个专门的格式解析类
效果图:
4bkkwceqsg5.JPG
-
- public enum ScriptType
- {
- Fraction,
- Italic,
- Tolerance
- }
- public static string MakeScript(string baseTextString, string superScript, string subScript, ScriptType scriptType, double scale)
- {
- string[] scriptTypStrings = new string[]{"/", "#", "^"};
- return
- string.Format
- (
- "\\A1;{0}{1}\\H{2:0.#}x;\\S{3}{4}{5};{6}",
- baseTextString,
- "{",
- scale,
- superScript,
- scriptTypStrings[(int)scriptType],
- subScript,
- "}"
- );
- }
- [CommandMethod("tt")]
- public static void Test()
- {
- var db = HostApplicationServices.WorkingDatabase;
- var doc = Application.DocumentManager.GetDocument(db);
- var ed = doc.Editor;
- using(Transaction tr = db.TransactionManager.StartTransaction())
- {
- MText mt =
- new MText
- {
- Contents = MakeScript("123", "+0.01", "-0.01", ScriptType.Tolerance, 0.5)
- };
- mt.SetDatabaseDefaults();
- var btr = db.CurrentSpaceId.GetObject[B](OpenMode.ForWrite);
- btr.AppendEntity(mt);
- tr.AddNewlyCreatedDBObject(mt, true);
- tr.Commit();
- }
- }
|