Here is sample code to add MText when a user picks cell from Table.
You either pass RTF contents to MText or create string with Format codes.
static public void addMtext() { Document document = Application.DocumentManager.MdiActiveDocument; Editor ed = document.Editor; Database db = document.Database; PromptNestedEntityOptions pneo = new PromptNestedEntityOptions(""); pneo.Message = "\nSelect a table cell text : "; PromptNestedEntityResult pner = ed.GetNestedEntity(pneo); if (pner.Status != PromptStatus.OK) return; Point3d pickedPt = pner.PickedPoint; ObjectId tableId = ObjectId.Null; ObjectId[] containers = pner.GetContainers(); if (containers.Length > 0) { tableId = containers[0]; } using(Transaction tr = db.TransactionManager.StartTransaction()) { Table table = tr.GetObject( tableId, OpenMode.ForWrite ) as Table; if (table != null) { TableHitTestInfo htinfo = table.HitTest( pickedPt, Vector3d.ZAxis ); ed.WriteMessage( "\nRow : {0} - Column : {1}", htinfo.Row, htinfo.Column ); //clear any style overrirdes. table.Cells[htinfo.Row, htinfo.Column].ClearStyleOverrides(); //create a Mtext and pass RTF contents MText mt = new MText(); mt.SetContentsRtf(@ "{\pntext\f0 1.\tab}First Line\par{\pntext\f0 2.\tab}Second Line\par}"); //or //pass contents "1.\tFirst Line\\P2.\tSecond Line\\P" table.Cells[htinfo.Row, htinfo.Column].TextString = "1.\tFirst Line\\P2.\tSecond Line\\P"; //mt.Contents; } tr.Commit(); }
Result: