@mehdi-guida I'm not sure if this is the best way to do it, but it seems to work on the Mtext objects I've tested with.
[CommandMethod("ShowMtextAnnoScale")]
public void showmtextscale()
{
var doc = Application.DocumentManager.MdiActiveDocument;
var ed = doc.Editor;
var db = doc.Database;
var entPrompt = new PromptEntityOptions("\nSelect an Mtext:");
entPrompt.SetRejectMessage("...not an Mtext object.");
entPrompt.AddAllowedClass(typeof(MText), true);
var entSel = ed.GetEntity(entPrompt);
if (entSel.Status != PromptStatus.OK)
return;
ObjectContextManager ocm = db.ObjectContextManager;
ObjectContextCollection occ = ocm.GetContextCollection("ACDB_ANNOTATIONSCALES");
using (Transaction tr = db.TransactionManager.StartTransaction())
{
var mtext = (MText)tr.GetObject(entSel.ObjectId, OpenMode.ForRead);
if(mtext.Annotative == AnnotativeStates.False)
{
ed.WriteMessage("\nSelected Mtext not annotative!");
return;
}
//the ObjectContexts class is in the Autodesk.AutoCAD.Internal namespace
var oContexts = ObjectContexts.GetContexts(mtext, occ.Name);
var scale = "";
foreach( var context in oContexts )
{
if (context.Name == occ.CurrentContext.Name)
{
scale = occ.CurrentContext.Name;
break;
}
scale = oContexts[0].Name;
}
ed.WriteMessage("\nSelected Mtext has the current annoscale of {0}.", scale);
}
}
Thank You So So So much for reply.
The only error I couldn't solve that is :
Thank you
I already used that. but its color shows it never used.
No, but when I add Acmgd.dll the Acdbmgd.dll automatically will be removed and I get a lot of error.
That does seem strange. Again, what year AutoCAD are you referencing?
Here are the references that I use and I do not have any issues.
I removed references and added them again and everything OK now. Thank you 🙂
Thank you so much my Hero 🙂