Get Annotation Scale of Mtext

Get Annotation Scale of Mtext

mehdi-guida
Advocate Advocate
984 Views
9 Replies
Message 1 of 10

Get Annotation Scale of Mtext

mehdi-guida
Advocate
Advocate

Hi

How can I get annotation scale (of mtext) by .net?

mehdiguida_3-1709829308910.png

 

0 Likes
Accepted solutions (1)
985 Views
9 Replies
Replies (9)
Message 2 of 10

Jeff_M
Consultant
Consultant
Accepted solution

@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);
            }
        }
Jeff_M, also a frequent Swamper
EESignature
Message 3 of 10

mehdi-guida
Advocate
Advocate

Thank You So So So much for reply.

The only error I couldn't solve that is :

mehdiguida_0-1710428907721.png

 

 

0 Likes
Message 4 of 10

hippe013
Advisor
Advisor

Add the following: 

Using Autodesk.AutoCAD.Internal;

 

0 Likes
Message 5 of 10

mehdi-guida
Advocate
Advocate

Thank you

I already used that. but its color shows it never used. 

mehdiguida_1-1710430117643.png

 

0 Likes
Message 6 of 10

hippe013
Advisor
Advisor

Thats weird. What year software are you using? 

Do you have a reference to the Acmgd.dll?  

0 Likes
Message 7 of 10

mehdi-guida
Advocate
Advocate

No, but when I add Acmgd.dll the Acdbmgd.dll automatically will be removed and I get a lot of error.

0 Likes
Message 8 of 10

hippe013
Advisor
Advisor

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. 

 

hippe013_0-1710435725956.png

 

 

0 Likes
Message 9 of 10

mehdi-guida
Advocate
Advocate

I removed references and added them again and everything OK now. Thank you 🙂

Message 10 of 10

mehdi-guida
Advocate
Advocate

Thank you so much my Hero 🙂