using System;
using System.Runtime.InteropServices;
using System.Reflection;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using AcRx = Autodesk.AutoCAD.Runtime;
using AcAp = Autodesk.AutoCAD.ApplicationServices;
using AcDb = Autodesk.AutoCAD.DatabaseServices;
using AcGe = Autodesk.AutoCAD.Geometry;
using AcEd = Autodesk.AutoCAD.EditorInput;
// This line is not mandatory, but improves loading performances
[assembly: CommandClass(typeof(MTextIndex.MyCommands))]
namespace MTextIndex
{
public class MyCommands
{
public MTextFragmentCallbackStatus
MTextCallback(MTextFragment frag, object userData)
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
string fragText = frag.Text;
if (frag.StackBottom)
{
ed.WriteMessage("\nНижний индекс: \"{0}\"", fragText);
}
else if (frag.StackTop)
{
ed.WriteMessage("\nВерхний индекс: \"{0}\"", fragText);
}
return MTextFragmentCallbackStatus.Continue;
}
[CommandMethod("TestMText")]
public void TestMText()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
PromptEntityResult per = ed.GetEntity("Выберите MText для проверки :");
if (per.Status != PromptStatus.OK)
return;
if (!per.ObjectId.ObjectClass.IsDerivedFrom(RXClass.GetClass(typeof(MText))))
{
ed.WriteMessage("Это не MText!");
return;
}
using (MText mtext = per.ObjectId.Open(OpenMode.ForRead) as MText)
{
mtext.ExplodeFragments(new MTextFragmentCallback(MTextCallback));
}
}
}
}