Use API “ExplodeFragments” as shown in below code to break the Mtext text string into fragments. The callback provided as input to “ExplodeFragments” is called for every Fragment of Mtext object.
static public MTextFragmentCallbackStatus
Fragments(MTextFragment Param, object data)
{
string strText = Param.Text;
//show the Fragmentted text.
Application.ShowAlertDialog(strText);
return MTextFragmentCallbackStatus.Continue;
}
[CommandMethod("ExplodeFragments")]
static public void ExplodeFragments()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
PromptEntityOptions options =
new PromptEntityOptions("nSelect a Mtext");
options.SetRejectMessage("nSelect only Mtext");
options.AddAllowedClass(typeof(MText), false);
PromptEntityResult acSSPrompt = ed.GetEntity(options);
if (acSSPrompt.Status != PromptStatus.OK)
return;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
try
{
MText text = tr.GetObject(acSSPrompt.ObjectId,
OpenMode.ForRead) as MText;
text.ExplodeFragments(Fragments, "Test");
tr.Commit();
}
catch
{
tr.Abort();
}
}
}

Leave a Reply