1

I am writing an application where one of the things it does is create a point then creates buffer (which is a graphic) at the specific point, what I want to do is when the buffer has been created, is to zoom to the extent of the buffer.

I have tried the following code but it doesn't seem to work

Dim penv2 As IEnvelope
Set penv2 = New Envelope
Set penv2 = pActiveView.extent
Dim pArea As IArea
Set pArea = pElement.Geometry.Envelope
penv2.CenterAt pArea.Centroid            
pActiveView.Refresh

I've also tried

Dim penv2 As IEnvelope
Set penv2 = pElement.Geometry.Envelope
pActiveView.Extent = penv2 
pActiveView.Refresh 

But nothing happens. Any ideas on where I am going wrong?

Thanks

1 Answer 1

1

This works for me:

Option Explicit
Sub ZoomToElement()
    Dim pMxDoc As IMxDocument
    Set pMxDoc = ThisDocument

    Dim pGCS As IGraphicsContainerSelect
    Set pGCS = pMxDoc.FocusMap

    If pGCS.ElementSelectionCount <> 1 Then
        Debug.Print "select just one element first"
        Exit Sub
    End If

    Dim pEnv As IEnvelope
    Set pEnv = pGCS.SelectedElement(0).Geometry.Envelope

    Dim pAV As IActiveView
    Set pAV = pMxDoc.FocusMap

    pAV.Extent = pEnv
    pAV.Refresh
End Sub

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.