Author Topic: Change leader annotation point  (Read 631 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
Change leader annotation point
« on: January 08, 2013, 06:19:14 PM »
Tested on A2010 only, for other release it's may be a different solution
Code: [Select]
      [CommandMethod("ChangeLeaderAnnoPoint", "clap", CommandFlags.Modal | CommandFlags.UsePickSet | CommandFlags.Redraw)]
        public void MoveLeaderAnno()
        {

            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;

            Editor ed = doc.Editor;

            Database db = doc.Database;

            Transaction tr = doc.TransactionManager.StartTransaction();

            using (tr)
            {

                PromptEntityOptions peo = new PromptEntityOptions("\nPlease pick leader >>");
                peo.SetRejectMessage("\nSelect Leader only >>");
                peo.AddAllowedClass(typeof(Leader), false);
                PromptEntityResult res;
                res = ed.GetEntity(peo);
                if (res.Status != PromptStatus.OK)
                    return;
                Entity ent = (Entity)tr.GetObject(res.ObjectId, OpenMode.ForRead);
                if (ent == null)
                    return;
                Leader ld = (Leader)ent as Leader;
                if (ld == null) return;

                ld.UpgradeOpen();
                Point3d oldPt = ld.LastVertex;
                ObjectId aid = ld.Annotation;
                Entity anno = tr.GetObject(aid, OpenMode.ForWrite) as Entity;
                if (anno == null) return;

                if (!anno.IsWriteEnabled) anno.UpgradeOpen();
                Point3d newPt;

                PromptPointOptions ppo = new PromptPointOptions("\nNew annotation point");
                PromptPointResult ppr = ed.GetPoint(ppo);
                if (ppr.Status != PromptStatus.OK) return;

                if (ppr.Status != PromptStatus.OK) return;
                newPt = ppr.Value;
                ed.WriteMessage("\nNew annotation point: {0}\n", newPt);
                Vector3d offset = newPt - oldPt;

                anno.TransformBy(Matrix3d.Displacement(offset));

                tr.Commit();
            }
        }
« Last Edit: January 22, 2013, 08:29:33 AM by fixo »