.NET

Reply
Contributor
sfinch1
Posts: 12
Registered: ‎01-24-2007
Message 1 of 18 (605 Views)

Zoom from modal dialog

605 Views, 17 Replies
12-28-2012 02:14 PM

I have an app that uses a paletteset.  The paletteset displays a modal dialog on a particular action.  From the modal dialog, the user needs to be able to click a button to zoom to a particular coordinate.  I have it all working, with one problem.  The Zoom doesn't occur until the user closes the modal dialog.  I know this is related to my limited understanding of contexts in AutoCAD, and am hoping that someone can point me in the right direction.

 

I've tried calling my Zoom method from the modal dialog, from the parent paletteset, and asynchronously using doc.SendStringToExecute() back to my main commands class, with the same result.  The Zoom occurs after exiting the modal dialog.

 

Any advice on how I can make the zoom occur while remaining in the modal dialog?

 

Thanks!

Valued Mentor
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 2 of 18 (583 Views)

Re: Zoom from modal dialog

12-28-2012 11:46 PM in reply to: sfinch1

You can't really get much help without showing some code, It's difficult to guess what your code is doing.

 

For example, how exactly, are you performing the ZOOM in the click handler?

Contributor
autodeskprogrammer
Posts: 21
Registered: ‎08-20-2008
Message 3 of 18 (565 Views)

Re: Zoom from modal dialog

12-29-2012 02:09 PM in reply to: DiningPhilosopher

I am not sure but maybe it can help you, but if is possible for you please put your current Code here then we can help you better.

 private static void ZoomWin(
      Editor ed, Point3d min, Point3d max
    )
    {
      Point2d min2d = new Point2d(min.X, min.Y);
      Point2d max2d = new Point2d(max.X, max.Y);

      ViewTableRecord view =
        new ViewTableRecord();

      view.CenterPoint =
        min2d + ((max2d - min2d) / 2.0);
      view.Height = max2d.Y - min2d.Y;
      view.Width = max2d.X - min2d.X;
      ed.SetCurrentView(view);
    }

 

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 4 of 18 (561 Views)

Re: Zoom from modal dialog

12-29-2012 03:23 PM in reply to: autodeskprogrammer

You wrote

>>I am not sure but maybe it can help you

Do you know who is DiningPhilosopher?

LOL

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Contributor
autodeskprogrammer
Posts: 21
Registered: ‎08-20-2008
Message 5 of 18 (521 Views)

Re: Zoom from modal dialog

12-31-2012 07:43 AM in reply to: Hallex

No I don't know who is he? 

Moderator
Alexander.Rivilis
Posts: 1,432
Registered: ‎04-09-2008
Message 6 of 18 (512 Views)

Re: Zoom from modal dialog

12-31-2012 12:40 PM in reply to: autodeskprogrammer

autodeskprogrammer wrote:

No I don't know who is he? 


Then read: http://forums.autodesk.com/t5/NET/What-happens-with-Tony-Tanzillo/td-p/2800448


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

Contributor
sfinch1
Posts: 12
Registered: ‎01-24-2007
Message 7 of 18 (463 Views)

Re: Zoom from modal dialog

01-02-2013 09:55 AM in reply to: DiningPhilosopher

Sorry for the delay in responding.  I was travelling and just got back.  Thanks for the replies.

 

I was trying to be concise by not posting pages of code, but I know I could have done a better job of explaining.  First, I should mention that I am using AutoCAD Map 3D and there is an FDO data layer involved, BUT I don't believe that has anything to do with the issue I'm facing.  (Maybe I'm wrong, though...)

 

I'm trying to Zoom to a specific X,Y point - either at the same scale or at a specific zoom scale.  I was originally using the Zoom code in the documentation called "Manipulate the Current View" here:

http://docs.autodesk.com/ACD/2013/DEU/index.html?url=files/GUID-FAC1A5EB-2D9E-497B-8FD9-E11D2FF87B93...

No matter what I tried, the Zooms would take me out in space somewhere.  I tried a lot of different things,but never could get it to Zoom to the right place.  Apparently, the transformations don't take into account the Map 3D coordinate system assigned.

 

I then discovered the Map API call AcMapMap.ZoomToExtent() using an MgEnvelope object.  This works correctly for me using this code:

    Public Shared Sub ZoomMapCenter(ZoomCenterPoint As Point3d, ObjectHeight As Double)
        'zoom to a specific point on the map at a reasonable zoom scale to view object

        Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
        Dim db As Database = doc.Database
        Dim ed As Editor = doc.Editor


        ZoomCenterPoint.TransformBy(ed.CurrentUserCoordinateSystem)

        Dim map As AcMapMap = AcMapMap.GetCurrentMap()
        Dim mapExtent As MgEnvelope = map.GetMapExtent()

        'There is some FDO feature source connected
        If Not mapExtent.IsNull() Then

            Dim centerX As Double = ZoomCenterPoint.X
            Dim centerY As Double = ZoomCenterPoint.Y

            'ed.WriteMessage("center:" & centerX.ToString() & "," & centerY.ToString() & vbLf)

            Dim newExtent As New MgEnvelope(ZoomCenterPoint.X - (ObjectHeight * 3.0), ZoomCenterPoint.Y - (ObjectHeight * 2.0), ZoomCenterPoint.X + (ObjectHeight * 3.0), ZoomCenterPoint.Y + (ObjectHeight * 2.0))

            map.ZoomToExtent(newExtent)

        Else
            'no FDO data source, use AutoCAD API

            Using Tx As Transaction = db.TransactionManager.StartTransaction()
                ed.UpdateTiledViewportsInDatabase()

                Dim viewportTableRec As ViewportTableRecord = TryCast(Tx.GetObject(ed.ActiveViewportId, OpenMode.ForWrite), ViewportTableRecord)

                viewportTableRec.CenterPoint = New Point2d(ZoomCenterPoint.X, ZoomCenterPoint.Y)


                ed.UpdateTiledViewportsFromDatabase()

                Tx.Commit()

            End Using

        End If

    End Sub

 

 

Again, everything works just fine and I'm getting the results I need, except for the fact that the view does not change until the user closes the modal dialog.  The zoom then occurs as expected and recenters the map on the correct location.  I just need for the Zoom to occur when the user clicks the button.

 

The button calling this function is on a modal form which is launched from a paletteset.  At the moment, I am trying by placing the ZoomMapCenter method above in my command class, calling it asynchronously using SendStringToExecute as shown below:

    Private Sub btnZoomTo_Click(sender As System.Object, e As System.EventArgs) Handles btnZoomTo.Click
        'zoom to the correct coordinates

        Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
        Dim ed As Editor = doc.Editor

        'zoom to the point based on the selected InventoryID

        If Not CurrentPoint.Equals(New Point3d()) = True Then

            Using edUsrInt As EditorUserInteraction = ed.StartUserInteraction(Me.Handle)


                'zoom to the point
                Dim centerPoint As String = CurrentPoint.X.ToString + "," + CurrentPoint.Y.ToString
                Dim stringToExecute As String = "ZoomToPlant " + centerPoint + " " + CurrentPlantBlockScale.ToString() + " "

                doc.SendStringToExecute(stringToExecute, True, False, False)

                edUsrInt.End()
                Me.Focus()

            End Using

        End If

    End Sub

 I also tried it without using the ed.StartUserInteraction() with no success.

 

Again, everything works just fine except that the view doesn't change until the user closes the modal form.  I'm sure the problem is related to me not fully understanding the session/document context that I'm running under.

 

Thanks for your help.

 

*Expert Elite*
norman.yuan
Posts: 1,017
Registered: ‎04-27-2009
Message 8 of 18 (456 Views)

Re: Zoom from modal dialog

01-02-2013 10:05 AM in reply to: sfinch1

Try call Editor.Regen() at the end of your ZoomMapCenter() method.

Moderator
Alexander.Rivilis
Posts: 1,432
Registered: ‎04-09-2008
Message 9 of 18 (441 Views)

Re: Zoom from modal dialog

01-02-2013 12:17 PM in reply to: sfinch1

Do you try to use Document.SendStringToExecute from button handler of modal dialog? Document.SendStringToExecute is executed asynchronously. That is why execution will be done only after command is ended. Try to call one of ZoomXXX function from this topic: http://forums.autodesk.com/t5/NET/ZoomWindow-and-ZoomScale/m-p/3249340#M26321

Also can be useful:

http://adndevblog.typepad.com/autocad/2012/04/synchronously-send-and-wait-for-commands-in-autocad-us...


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

Contributor
autodeskprogrammer
Posts: 21
Registered: ‎08-20-2008
Message 10 of 18 (422 Views)

Re: Zoom from modal dialog

01-02-2013 05:25 PM in reply to: sfinch1

but I implemented your code and it worked perfectly - only I disabled some part of your code 

 Public Shared Sub ZoomMapCenter(ZoomCenterPoint As Point3d, ObjectHeight As Double)
        'zoom to a specific point on the map at a reasonable zoom scale to view object

        Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
        Dim db As Database = doc.Database
        Dim ed As Editor = doc.Editor


        ZoomCenterPoint.TransformBy(ed.CurrentUserCoordinateSystem)

        'Dim map As AcMapMap = Nothing
        'AcMapMap.GetCurrentMap()
        'Dim mapExtent As MgEnvelope = Nothing
        'map.GetMapExtent()

        'There is some FDO feature source connected
        If False Then

            'Dim centerX As Double = ZoomCenterPoint.X
            'Dim centerY As Double = ZoomCenterPoint.Y

            ''ed.WriteMessage("center:" & centerX.ToString() & "," & centerY.ToString() & vbLf)

            'Dim newExtent As New MgEnvelope(ZoomCenterPoint.X - (ObjectHeight * 3.0), ZoomCenterPoint.Y - (ObjectHeight * 2.0), ZoomCenterPoint.X + (ObjectHeight * 3.0), ZoomCenterPoint.Y + (ObjectHeight * 2.0))

            'map.ZoomToExtent(newExtent)

        Else
            'no FDO data source, use AutoCAD API

            Using Tx As Transaction = db.TransactionManager.StartTransaction()
                ed.UpdateTiledViewportsInDatabase()

                Dim viewportTableRec As ViewportTableRecord = TryCast(Tx.GetObject(ed.ActiveViewportId, OpenMode.ForWrite), ViewportTableRecord)

                viewportTableRec.CenterPoint = New Point2d(ZoomCenterPoint.X, ZoomCenterPoint.Y)


                ed.UpdateTiledViewportsFromDatabase()

                Tx.Commit()

            End Using

        End If

    End Sub

 

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

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