AutoCAD Map 3D Developer

AutoCAD Map 3D Developer

Reply
Valued Contributor
newautocad123
Posts: 58
Registered: ‎09-03-2012
Message 1 of 3 (277 Views)

.net Zoom to a selected point

277 Views, 2 Replies
10-28-2012 09:55 PM

How can I zoom to a selected point programmatically?

 

Thanks.

Distinguished Contributor
djonio
Posts: 105
Registered: ‎12-29-2005
Message 2 of 3 (270 Views)

Re: .net Zoom to a selected point

10-29-2012 03:50 AM in reply to: newautocad123

Here is one way using COM. I just did a quick review and you might get an error if objectid is a Point object but this will get you going.

 

       static public void ZoomObject(ObjectId id, double zoomFactor)
        {
            Database db = HostApplicationServices.WorkingDatabase;
            AcadApplication app = (AcadApplication)Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;
            Point3d center;
            double zoomHeight = 0.0;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                object oMinpt = new object(), oMaxpt = new object();
                double[] dMinpt = new double[3], dMaxpt = new double[3];
                Entity en = (Entity)tr.GetObject(id, OpenMode.ForRead);
                AcadEntity en_com = en.AcadObject as AcadEntity;
                Object minPt = new Object(), maxPt = new Object();
                en_com.GetBoundingBox(out oMinpt, out oMaxpt);
                dMinpt = (double[])oMinpt; dMaxpt = (double[])oMaxpt;
                double heightEnt = dMaxpt[1] - dMinpt[1];
                double widthEnt = dMaxpt[0] - dMinpt[0];
                Object objRes = new Object(); objRes = app.ActiveDocument.GetVariable("SCREENSIZE");
                Point2d screenRes = new Point2d((double[])objRes);
                double aspectScreen = screenRes.Y / screenRes.X;
                double aspectEnt = heightEnt / widthEnt;
                if (aspectEnt < aspectScreen)
                {
                    zoomFactor *= (aspectEnt / aspectScreen);
                }
                center = new Point3d(
                (dMinpt[0] + dMaxpt[0]) * 0.5,
                (dMinpt[1] + dMaxpt[1]) * 0.5,
                (dMinpt[2] + dMaxpt[2]) * 0.5
                );
                zoomHeight = heightEnt * 100 / Math.Max(zoomFactor, 1e-6);
            }
            if (zoomHeight <= 0)
                zoomHeight = 1;

            app.ZoomCenter(center.ToArray(), zoomHeight);
        }

 r,

dennis

Valued Contributor
newautocad123
Posts: 58
Registered: ‎09-03-2012
Message 3 of 3 (257 Views)

Re: .net Zoom to a selected point

10-29-2012 08:26 PM in reply to: djonio

Thanks. It works as desired.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!