Message 1 of 4

Not applicable
02-01-2018
12:44 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi Team,
Unable to update Mtext please find below code.
Note: Please advice me there is any way to debug command code .
[CommandMethod("MyTestCommands", "test", CommandFlags.Modal)] public void Test() { var doc = Application.DocumentManager.MdiActiveDocument; var ed = doc.Editor; var res1 = ed.GetFileNameForOpen("Specify parameter file"); if (res1.Status != Autodesk.AutoCAD.EditorInput.PromptStatus.OK) return; var res2 = ed.GetString("Specify output sub-folder name"); if (res2.Status != Autodesk.AutoCAD.EditorInput.PromptStatus.OK) return; try { var db = doc.Database; using (Transaction tr = db.TransactionManager.StartTransaction()) { BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.BlockTableId, OpenMode.ForRead); foreach (ObjectId id in btr) { Entity currentEntity = tr.GetObject(id, OpenMode.ForWrite, false) as Entity; if (currentEntity == null) { continue; } if (currentEntity.GetType() == typeof(MText)) { ((MText)currentEntity).Contents = "BlahBlah"; } else { ((DBText)currentEntity).TextString = "BlahBlah"; } } tr.Commit(); } } catch (System.Exception e) { using (var writer = File.CreateText(Path.Combine(res2.StringResult, "error.txt"))) { writer.WriteLine(e.ToString()); } ed.WriteMessage("Error: {0}", e.ToString()); } }
Solved! Go to Solution.