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.