Author Topic: Help with zoomextends  (Read 753 times)

0 Members and 1 Guest are viewing this topic.

GEURT

  • Mosquito
  • Posts: 7
Help with zoomextends
« on: November 16, 2011, 12:00:20 am »
Hi,
I am new here and have a question.
As background, I have written a couple of C# modules, one to write Civil 3D networks to Epanet input text files (.inp) and another to read Epanet output text files (.inp) to pipe networks inside Civil 3D.

Now the question, after I have created all the pipes and structures inside Civil 3D, I'd like to fire a ZoomExtends instruction and I cannot find a way to do that. Can someone please help with that?

Thanks
Geurt

LE3

  • Guest
Re: Help with zoomextends
« Reply #1 on: November 16, 2011, 12:14:43 am »
Code: [Select]
        /// <summary>
        /// zoom to extents
        /// </summary>
        /// <param name="db">drawing database</param>
        static public void ZoomExtents(Database db)
        {
            Document doc = AcadApp.DocumentManager.MdiActiveDocument;
            Point3d max = db.Extmax;
            Point3d min = db.Extmin;
            Point2d max_2d = new Point2d(max.X, max.Y);
            Point2d min_2d = new Point2d(min.X, min.Y);
            ViewTableRecord view = new ViewTableRecord();
            view.CenterPoint = (min_2d + (max_2d - min_2d) / 2.0);
            view.Height = (max_2d.Y - min_2d.Y);
            view.Width = (max_2d.X - min_2d.X);
            doc.Editor.SetCurrentView(view);
            db.UpdateExt(true);
        }

        [CommandMethod("ZE")]
        public static void zoome()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            ZoomExtents(db);
        }

gile

  • Water Moccasin
  • Posts: 1741
  • Marseille, France
Re: Help with zoomextends
« Reply #2 on: November 16, 2011, 01:04:54 am »
Hi,

This one works whatever the view direction.

Code: [Select]
        public static void ZoomExtents(this Editor ed, Database db)
        {
             using (ViewTableRecord view = ed.GetCurrentView())
            {
                Extents3d extents = new Extents3d(db.Extmin, db.Extmax);
                Matrix3d WCS2DCS =
                    Matrix3d.Rotation(-view.ViewTwist, view.ViewDirection, view.Target) *
                    Matrix3d.Displacement(view.Target - Point3d.Origin) *
                    Matrix3d.PlaneToWorld(view.ViewDirection);
                extents.TransformBy(WCS2DCS.Inverse());
                Point2d center = new Point2d(
                    (extents.MinPoint.X + extents.MaxPoint.X) / 2.0,
                    (extents.MinPoint.Y + extents.MaxPoint.Y) / 2.0);
                view.Height = (extents.MaxPoint.Y - extents.MinPoint.Y);
                view.Width = (extents.MaxPoint.X - extents.MinPoint.X);
                view.CenterPoint = center;
                ed.SetCurrentView(view);
                db.UpdateExt(true);
            }
        }

        [CommandMethod("ze")]
        public void ZoomExtentsCmd()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            doc.Editor.ZoomExtents(doc.Database);
        }
Speaking English as a French Frog

GEURT

  • Mosquito
  • Posts: 7
Re: Help with zoomextends
« Reply #3 on: November 16, 2011, 02:04:59 am »
Thanks a million and elegant as well. I was fideling in a totally different direction (interop area) and was walking into walls the whole time.

Cheers
Geurt

GEURT

  • Mosquito
  • Posts: 7
Re: Help with zoomextends
« Reply #4 on: November 17, 2011, 04:42:46 am »
Okay got an "interop" version going as follows:

public static AcadDocument ThisDrawing
{
     get
     {
          return (AcadDocument)Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.AcadDocument;
     }
}


public static void ZoomExtents()
{       
     ThisDrawing.Application.ZoomExtents();
}

Cheers
Geurt

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 10819
  • class keyThumper<T>:ILazy<T>
Re: Help with zoomextends
« Reply #5 on: November 17, 2011, 11:03:58 pm »
[catSkinning++]

And with SendStringToExecute

Code: [Select]
AcadApp.DocumentManager.MdiActiveDocument.SendStringToExecute("Zoom e\n", false, false, false);
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate<--