When this method is used to explode an MText entity that makes use of control codes such as "%%c", "%%d" then the fragment text in the callback method will contain the control code and not the special character that it represents. A simple workaround to get the text fragment is to create a MText and sets its content based on the fragment text. Here is a sample code snippet :

public MTextFragmentCallbackStatus MTextCallback

(MTextFragment frag, object userData)

{

Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

String fragText = frag.Text;

ed.WriteMessage(String.Format("{0} Fragment : {1}",

Environment.NewLine, fragText));

using (MText mt = new MText())

{

mt.SetDatabaseDefaults();

mt.Contents = fragText;

String mtText = mt.Text;

ed.WriteMessage(String.Format("{0} Fragment : {1}",

Environment.NewLine, mtText));

}

return MTextFragmentCallbackStatus.Continue;

}

[CommandMethod("TestMText")]

publicvoid TestMText()

{

Document doc = Application.DocumentManager.MdiActiveDocument;

Database db = doc.Database;

Editor ed = doc.Editor;

PromptEntityResult per

= ed.GetEntity("Select MText to explode :");

if (per.Status != PromptStatus.OK)

return;

using (Transaction Tx = db.TransactionManager.StartTransaction())

{

MText mtext =

(MText)Tx.GetObject(per.ObjectId, OpenMode.ForRead);

mtext.ExplodeFragments(

new MTextFragmentCallback(MTextCallback));

Tx.Commit();

}

}

Here is the output of the code snippet on a sample MText that uses %%c and %%d :

When this method is used to explode an MText entity that makes use of control codes such as "%%c", "%%d" then the fragment text in the callback method will contain the control code and not the special character that it represents. A simple workaround to get the text fragment is to create a MText and sets its content based on the fragment text. Here is a sample code snippet :

public MTextFragmentCallbackStatus MTextCallback

(MTextFragment frag, object userData)

{

Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

String fragText = frag.Text;

ed.WriteMessage(String.Format("{0} Fragment : {1}",

Environment.NewLine, fragText));

using (MText mt = new MText())

{

mt.SetDatabaseDefaults();

mt.Contents = fragText;

String mtText = mt.Text;

ed.WriteMessage(String.Format("{0} Fragment : {1}",

Environment.NewLine, mtText));

}

return MTextFragmentCallbackStatus.Continue;

}

[CommandMethod("TestMText")]

publicvoid TestMText()

{

Document doc = Application.DocumentManager.MdiActiveDocument;

Database db = doc.Database;

Editor ed = doc.Editor;

PromptEntityResult per

= ed.GetEntity("Select MText to explode :");

if (per.Status != PromptStatus.OK)

return;

using (Transaction Tx = db.TransactionManager.StartTransaction())

{

MText mtext =

(MText)Tx.GetObject(per.ObjectId, OpenMode.ForRead);

mtext.ExplodeFragments(

new MTextFragmentCallback(MTextCallback));

Tx.Commit();

}

}

Here is the output of the code snippet on a sample MText that uses %%c and %%d :