How to create a flyby-from-path animation


This sample shows you how to create a Flyby-From-Path animation in ArcMap. It requires a line feature layer as the flyby path to work.

How to use

  1. Open ArcMap and add a feature or raster layer to the ArcMap TOC;
  2. Add a line feature layer to the TOC as the flyby path;
  3. Organize the layers in the TOC, so that the line feature layer is the second layer;
  4. Copy and paste the following code into the VB editor in ArcMap;
  5. Make sure that "ESRI Animation Object Library" and "ESRI AnimationUI Object Library" are checked in the References dialog box of the VBA project;
  6. Run the macro "Create_FlybyFromPath_Animation";
  7. Click the Animation dropdown on the Animation toolbar and click Animation Manager. In the Animation Manager dialog box, click the Tracks tab to verify that a new track from path has been created.
[VBA]
Public Sub Create_FlybyFromPath_Animation()
    'Find the animation extension
    Dim pUID As New UID
    pUID.Value = "esriAnimation.AnimationExtension"
    Dim pAnimExt As IAnimationExtension
    Set pAnimExt = Application.FindExtensionByCLSID(pUID)
    
    Dim pMxDoc As IMxDocument
    Set pMxDoc = ThisDocument
    Dim pMap As IMap
    Set pMap = pMxDoc.Maps.Item(0)
    
    'Get the line feature in the path layer
    Dim pLayer As ILayer
    Set pLayer = pMap.Layer(1)
    
    Dim pFClass As IFeatureClass
    Dim pFLayer As IFeatureLayer
    Set pFLayer = pLayer
    Set pFClass = pFLayer.FeatureClass
    Dim pFeature As IFeature
    Set pFeature = pFClass.GetFeature(0)
    
    'Get the geometry of the line feature
    Dim pGeom1 As IGeometry
    Set pGeom1 = pFeature.Shape
    
    'Create AGAnimationUtils and AGImportPathOptions objects
    Dim pAGAnimUtils As IAGAnimationUtils
    Set pAGAnimUtils = New AGAnimationUtils
    Dim pAGImpOptions As IAGImportPathOptions
    Set pAGImpOptions = New AGImportPathOptions
    
    'Set properties for AGImportPathOptions
    Set pAGImpOptions.AnimatedObject = pMap 'Animation object is the map
    Set pAGImpOptions.AnimationType = New AnimationTypeMapView
    Set pAGImpOptions.AnimationTracks = pAnimExt.AnimationTracks
    pAGImpOptions.PathGeometry = pGeom1
    Set pAGImpOptions.AnimationEnvironment = pAnimExt.AnimationEnvironment
    
    Dim pBasicMap As IBasicMap
    Set pBasicMap = pMap 'QI
    Set pAGImpOptions.BasicMap = pBasicMap
    
    Dim pAnimContainer As IAGAnimationContainer
    Set pAnimContainer = pAnimExt.AnimationTracks.AnimationObjectContainer
    
    'Call "CreateFlybyFromPath"
    pAGAnimUtils.CreateFlybyFromPath pAnimContainer, pAGImpOptions
    
End Sub