.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

zoom extents issue after drawing window resize

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
btmcad
2165 Views, 4 Replies

zoom extents issue after drawing window resize

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

 

 

 

 

4 REPLIES 4
Message 2 of 5
Alexander.Rivilis
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);
}

 ?

 

 

 

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 3 of 5

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.

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 4 of 5
btmcad
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

Message 5 of 5
sszabo
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 😉

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost