.NET

Reply
Contributor
Posts: 15
Registered: ‎08-09-2013
Message 1 of 2 (86 Views)

how can i get mtext properties

86 Views, 1 Replies
09-26-2013 08:18 PM

i want to get the mtext font, height and width

 

Dim acDoc As Document = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database

Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()

Dim bt As BlockTable
bt = acTrans.GetObject(acCurDb.BlockTableId, _
OpenMode.ForRead)

Dim btRec As BlockTableRecord

btRec = acTrans.GetObject(bt(BlockTableRecord.ModelSpace), _
OpenMode.ForRead)

Dim ts As TextStyleTable = acTrans.GetObject(acCurDb.TextStyleTableId, _
OpenMode.ForRead)

For Each mtstyleid As ObjectId In ts

 

..........


Next

*Expert Elite*
Hallex
Posts: 1,557
Registered: ‎10-08-2008
Message 2 of 2 (63 Views)

Re: how can i get mtext properties

09-27-2013 12:06 AM in reply to: hoyin0820

This will get you started, you have just to translate the code on vb.net by yourself^

        [CommandMethod("mxx")]
        public void mxprops()
        {
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;

            PromptEntityOptions peo = new PromptEntityOptions("\nSelect the mtext to get properties: ");
            peo.SetRejectMessage("Only a mtext !");
            peo.AddAllowedClass(typeof(MText), false);
            PromptEntityResult per = ed.GetEntity(peo);
            if (per.Status != PromptStatus.OK) return;
            ObjectId id = per.ObjectId;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                Entity ent = tr.GetObject(id, OpenMode.ForWrite) as Entity;
                MText mtx = ent as MText;
                if (mtx != null)
                {
                    List<object> lst = GetMtextProperties(mtx);
                    foreach (object item in lst)
                        ed.WriteMessage("\n\t{0}\n", item);
                }
            }
        }
        public static List<object> GetMtextProperties(MText mtx)
        {
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;
            List<object> data = new List<object>();
            int nCol = -1;
            ObjectId tstyleID = ObjectId.Null;

            if (mtx != null)
            {
                nCol = mtx.ColorIndex;
                tstyleID = mtx.TextStyleId;
                TextStyleTable tsTbl = db.TextStyleTableId.GetObject(OpenMode.ForRead) as TextStyleTable;
                if (tsTbl == null) return null;
                TextStyleTableRecord tsTblRec = mtx.TextStyleId.GetObject(OpenMode.ForRead) as TextStyleTableRecord;
                data.Add(tsTblRec.Name); // style name
                data.Add(tsTblRec.FileName);// font name
                data.Add(mtx.TextHeight);// textsize
                data.Add(mtx.ActualHeight);// mtext frame height
                data.Add(mtx.ActualWidth); // mtext frame width
                // <---add other properties you need...
            }
            return data;
        }

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community