Author Topic: Add vertex to MLeader  (Read 867 times)

0 Members and 1 Guest are viewing this topic.

Offline fixo

  • Full Member
  • ***
  • Posts: 135
  • Karma: +4/-0
  • Gender: Male
    • prefered language: C
    • Prog expertise: Good
    • View Profile
Add vertex to MLeader
« on: July 23, 2012, 09:10:14 AM »
Code: [Select]
   //tested on AutoCAD 2010
       [CommandMethod("AddVertexToMLeader", "mlv", CommandFlags.Redraw)]
        public void AddMleaderVx()
        {
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;

            Editor ed = doc.Editor;

            Database db = doc.Database;
     
            try
            {
                PromptEntityOptions peo =
                 new PromptEntityOptions("\nSelect mleader: ");
                peo.SetRejectMessage("\nMust be select type of MLeader.");
                peo.AddAllowedClass(typeof(MLeader), false);

                PromptEntityResult per = ed.GetEntity(peo);
                if (per.Status != PromptStatus.OK) return;
                ObjectId txtId = per.ObjectId;
                PromptPointOptions opt = new PromptPointOptions("\nSpecify new vertex location: ");
                PromptPointResult res = ed.GetPoint(opt);

                if (res.Status != PromptStatus.OK) return;

                Point3d vp = res.Value;

                using (Transaction tr = db.TransactionManager.StartTransaction())
                {

                    BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;

                    DBObject obj = (DBObject)tr.GetObject(txtId, OpenMode.ForWrite) as DBObject;

                    MLeader leader = obj as MLeader;
   
                    int ld = leader.AddLeader();
                    int ln = leader.AddLeaderLine(ld);
                    leader.AddFirstVertex(ln, vp);
                    leader.AddLastVertex(ln, leader.TextLocation);

                    tr.Commit();
                }
            }
            catch (System.Exception ex)
            {
                ed.WriteMessage("\nError: {0}\nTrace: {1}", ex.Message, ex.StackTrace);
            }
            finally
            {
           
            }
        }

~'J'~