.NET

Reply
Active Contributor
btmcad
Posts: 31
Registered: ‎05-09-2007
Message 1 of 5 (898 Views)
Accepted Solution

zoom extents issue after drawing window resize

898 Views, 4 Replies
02-16-2013 12:36 PM

I'm working on a program that resizes the current drawing window to a specific size, then performs a zoom extents.

So far, I can get the window to resize properly, but the drawing will not properly zoom to the extents. After the window is resized, the drawing zooms, and is approximately centered on the screen, but the objects run off the edges of the drawing window. I attached an image below that uses a circle as an example. I also included my code below. If I run this code a second time, on the very same drawing, then it zooms properly. It seems that once the window is already set to the proper size then the zoom works. It seems like the Entmax and Entmin properties do not properly update until after the program has completed. Is there a way around this? I could write this in two different programs, and get it to work, but I would really like to find a solution to get this working within a single program / command.

I've also posted this on theswamp, and there were some good suggestions for some different code to perform a zoom extents, but they do not fix the issue described above.

I would greatly appreciate any suggestions or help.

 

 

Public Sub Main()

            Dim doc As Document = Application.DocumentManager.MdiActiveDocument()

            Dim ed As Editor = doc.Editor
            Dim docWindow As Window = doc.Window
            Dim db As Database = doc.Database

            docWindow.WindowState = Window.State.Normal
            Dim newSize As System.Drawing.Size = New System.Drawing.Size(950, 573) 'was 608
            docWindow.SetSize(newSize)


            Using docLoc As DocumentLock = doc.LockDocument
                db.UpdateExt(True)

                Dim ViewTableRecord As New ViewTableRecord

                Dim MaxPoint As Point3d = db.Extmax

                Dim MinPoint As Point3d = db.Extmin

                Dim MaxPoint2D As Point2d = New Point2d(MaxPoint.X, MaxPoint.Y)

                Dim MinPoint2D As Point2d = New Point2d(MinPoint.X, MinPoint.Y)

                ViewTableRecord.CenterPoint = MinPoint2D + (MaxPoint2D - MinPoint2D) * 0.5

                ViewTableRecord.Height = MaxPoint2D.Y - MinPoint2D.Y

                ViewTableRecord.Width = MaxPoint2D.X - MinPoint2D.X

                ed.SetCurrentView(ViewTableRecord)
            End Using

            
        End Sub

 

 

 

 

As far as I remember the actual window resizing occurs only after the command completes. This way I can recommend to do two commands:
1. The first command changes the size of the window and starts the second with AcadDocument.SendCommand or Document.SendStringToExecute
2. The second command executes Zoom Extents any of the proposed methods, as well as all the rest.

Moderator
Alexander.Rivilis
Posts: 1,416
Registered: ‎04-09-2008
Message 2 of 5 (882 Views)

Re: zoom extents issue after drawing window resize

02-16-2013 02:12 PM in reply to: btmcad

What about using such code for Zoom Extents:

public static void ZoomExtents()
{
  object acad = Application.AcadApplication;
  acad.GetType().InvokeMember("ZoomExtents",BindingFlags.Public |
               BindingFlags.InvokeMethod, null, acad, null);
}

 ?

 

 

 


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Moderator
Alexander.Rivilis
Posts: 1,416
Registered: ‎04-09-2008
Message 3 of 5 (872 Views)

Re: zoom extents issue after drawing window resize

02-16-2013 03:33 PM in reply to: Alexander.Rivilis

As far as I remember the actual window resizing occurs only after the command completes. This way I can recommend to do two commands:
1. The first command changes the size of the window and starts the second with AcadDocument.SendCommand or Document.SendStringToExecute
2. The second command executes Zoom Extents any of the proposed methods, as well as all the rest.


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Active Contributor
btmcad
Posts: 31
Registered: ‎05-09-2007
Message 4 of 5 (866 Views)

Re: zoom extents issue after drawing window resize

02-16-2013 05:32 PM in reply to: Alexander.Rivilis

Alexander,

I didn't try the first option you mentioned, but I will shortly.

I did split the program into two commands, and it works fine. I just used the sendstringtoexecute method.

Thank you for your input. I wasn't realizing that the window didn't resize until after the command finished.

 

btmcad

Valued Contributor
sszabo
Posts: 86
Registered: ‎09-05-2012
Message 5 of 5 (827 Views)

Re: zoom extents issue after drawing window resize

02-18-2013 02:12 PM in reply to: btmcad

I don't know this is what worked for me in the past.

 

Application.DocumentManager.MdiActiveDocument.Window.WindowState = Window.State.Maximized

Application.AcadApplication.ZoomExtents()

 

I've read a great tutorial on zooming that also contains full source code for an excellent zoom function in .NET that also seems to be working fine.

 

 

 Oops, never mind, now I see you posted the solution in the original question: that's the .NET API I was thinking of :smileywink:

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.