Zoom Oddity I have seen

Zoom Oddity I have seen

dennis
Advisor Advisor
1,904 Views
8 Replies
Message 1 of 9

Zoom Oddity I have seen

dennis
Advisor
Advisor

I use ZoomExtents, ZoomWindow, ZoomEntity, pretty much as described at:

http://through-the-interface.typepad.com/through_the_interface/2008/06/zooming-to-a-wi.html

I will get the Database.Extmin and Database.Extmax for the extents to feed to:

 

		public static void ZoomWin(Editor acEd, Point3d min, Point3d max)
		{
			Point2d min2d = new Point2d(min.X, min.Y);
			Point2d max2d = new Point2d(max.X, max.Y);
			ViewTableRecord view = new ViewTableRecord();
			Point3d vcen = MidpointPtPt(min2d, max2d);
			view.CenterPoint = new Point2d(vcen.X, vcen.Y);
			//view.CenterPoint = min2d + ((max2d - min2d) / 2.0);
			view.Height = max2d.Y - min2d.Y;
			view.Width = max2d.X - min2d.X;
			acEd.Regen();
			acEd.SetCurrentView(view);
		}

 

What I have found is that often, about every other time, it 'blacks out'.  I can then Set Next Statement back to the acEd.Regen(), then step on through and it will then show everything.  I have tried it with and without the Regen, but either way the results is the same.

While it is annoying, it isn't major, but if someone has an answer, I would appreciate it.

 

By the way, I have tried other methods for the Zoom Extents, and actually get the same results, half or so of the time it blacks out.

0 Likes
Accepted solutions (1)
1,905 Views
8 Replies
Replies (8)
Message 2 of 9

_gile
Consultant
Consultant

Hi,

 

For a Zoom extents have you try calling Database.UpdateExt() before getting Database.Extmin and Database.Extmax?

 

What if using the COM Zoom methods:

 

dynamic acadApp = Application.AcadApplication;
acadApp.ZoomExtents();

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 9

dennis
Advisor
Advisor

Giles,

I have tried the COM method as well, with same results.  Adding the acDb.UpdateExt(true) may have helped though.  I assume the true for BestFit is correct. It seems now it goes black fewer times.

0 Likes
Message 4 of 9

ambrosl
Autodesk
Autodesk

These topics and code samples might be helpful:

 

Manipulate the Current View (.NET)
http://help.autodesk.com/view/OARX/2018/ENU/?guid=GUID-FAC1A5EB-2D9E-497B-8FD9-E11D2FF87B93

 

Display Drawing Extents and Limits (.NET)
http://help.autodesk.com/view/OARX/2018/ENU/?guid=GUID-70B3140A-14F1-4F54-AF5F-8DEDB444C3BA



Lee Ambrosius
Senior Principal Content Experience Designer
For additional help, check out the AutoCAD Developer Documentation
0 Likes
Message 5 of 9

_gile
Consultant
Consultant
Accepted solution

The extension methods I use.

 

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Autodesk.AutoCAD.EditorInput
{
    public static class ExtensionMethods
    {
        public static Matrix3d EyeToWorld(this ViewTableRecord view)
        {
            if (view == null)
                throw new ArgumentNullException("view");

            return
                Matrix3d.Rotation(-view.ViewTwist, view.ViewDirection, view.Target) *
                Matrix3d.Displacement(view.Target - Point3d.Origin) *
                Matrix3d.PlaneToWorld(view.ViewDirection);
        }

        public static Matrix3d WorldToEye(this ViewTableRecord view)
        {
            return view.EyeToWorld().Inverse();
        }

        public static void Zoom(this Editor ed, Extents3d ext)
        {
            if (ed == null)
                throw new ArgumentNullException("ed");

            using (ViewTableRecord view = ed.GetCurrentView())
            {
                ext.TransformBy(view.WorldToEye());
                view.Width = ext.MaxPoint.X - ext.MinPoint.X;
                view.Height = ext.MaxPoint.Y - ext.MinPoint.Y;
                view.CenterPoint = new Point2d(
                    (ext.MaxPoint.X + ext.MinPoint.X) / 2.0,
                    (ext.MaxPoint.Y + ext.MinPoint.Y) / 2.0);
                ed.SetCurrentView(view);
            }
        }

        public static void ZoomCenter(this Editor ed, Point3d center, double scale = 1.0)
        {
            if (ed == null)
                throw new ArgumentNullException("ed");

            using (ViewTableRecord view = ed.GetCurrentView())
            {
                center = center.TransformBy(view.WorldToEye());
                view.Height /= scale;
                view.Width /= scale;
                view.CenterPoint = new Point2d(center.X, center.Y);
                ed.SetCurrentView(view);
            }
        }

        public static void ZoomExtents(this Editor ed)
        {
            if (ed == null)
                throw new ArgumentNullException("ed");

            Database db = ed.Document.Database;
            db.UpdateExt(false);
            Extents3d ext = (short)Application.GetSystemVariable("cvport") == 1 ?
                new Extents3d(db.Pextmin, db.Pextmax) :
                new Extents3d(db.Extmin, db.Extmax);
            ed.Zoom(ext);
        }

        public static void ZoomObjects(this Editor ed, IEnumerable<ObjectId> ids)
        {
            if (ed == null)
                throw new ArgumentNullException("ed");

            using (Transaction tr = ed.Document.TransactionManager.StartTransaction())
            {
                Extents3d ext = ids
                    .Where(id => id.ObjectClass.IsDerivedFrom(RXObject.GetClass(typeof(Entity))))
                    .Select(id => ((Entity)tr.GetObject(id, OpenMode.ForRead)).GeometricExtents)
                    .Aggregate((e1, e2) => { e1.AddExtents(e2); return e1; });
                ed.Zoom(ext);
                tr.Commit();
            }
        }

        public static void ZoomScale(this Editor ed, double scale)
        {
            if (ed == null)
                throw new ArgumentNullException("ed");

            using (ViewTableRecord view = ed.GetCurrentView())
            {
                view.Width /= scale;
                view.Height /= scale;
                ed.SetCurrentView(view);
            }
        }

        public static void ZoomWindow(this Editor ed, Point3d p1, Point3d p2)
        {
            using (Line line = new Line(p1, p2))
            {
                ed.Zoom(line.GeometricExtents);
            }
        }
    }
}


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 6 of 9

dennis
Advisor
Advisor

Lee, above, the code Gilles posted seems to be the same gist of the link you gave.  With the exceptions that the link uses a Line for some calcs and Gilles' code is an Extension.  Unless I am missing something...

0 Likes
Message 7 of 9

dennis
Advisor
Advisor

Gilles, I would have thought the database.UpdateExt() would have been true rather than false?  I appreciate seeing it done as an extension.  I discovered this technique a couple of months ago, and have been trying to build on that technique.  I had not thought of making the zooms into extensions. Kudos.

After a few test runs, it does seem to be updating more often now. 

There are still some oddities in my scenario, I Insert a block, then copy that block several times.  The view update doesn't occur following the Insert, does update after the first copy, misses the second copy, does update after the third, and so on, continues update after 'every other' copy.

Very weird...

0 Likes
Message 8 of 9

_gile
Consultant
Consultant

dennis a écrit :

Gilles, I would have thought the database.UpdateExt() would have been true rather than false?


From the docs:

 

"Setting the argument doBestFit to TRUE means that while traversing the database, any BlockReference entities found should have their geomExtentsBestFit() method called instead of geomExtents(). This will be slower but will generate a tighter bounding box (extents). Using the default argument of FALSE will be faster but may not produce the tightest bounding box."

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 9 of 9

dennis
Advisor
Advisor

Kudos Gilles.

I have resolved the problem.  By doing a little zooming manipulation.  Experimenting around, I found that if I ZoomObjects on the cloned blk, then follow that with the ZoomExtents, I see the series Insert, then Clone as many times as I need.  Your code made me learn a little too, specifically with the IEnumerable and, as well, I did not know I could reach the Database via the Editor (Editor.Document.Database).  Both have me now, looking through my existing code to see where I could utilize these two.

 

0 Likes