Create Animation from Path Snippet (ArcObjects .NET 10.6 SDK)
ArcObjects Library Reference

Create Animation from Path Snippet

Creates a camera animation from path. The path is supplied by specifying a specific line feature from a ILayer.

[C#]
///<summary>Creates a camera animation from path. The path is supplied by specifying a specific line feature from a ILayer.</summary>
/// 
///<param name="globe">An IGlobe interface</param>
///<param name="layer">An ILayer interface that is a Polyline</param>
///<param name="featureID">A System.Int32 that is the FeatureID record number for which the fly by is to follow to create the animation. Example: 123</param>
///  
///<remarks></remarks>
public void CreateAnimationFromPath(ESRI.ArcGIS.GlobeCore.IGlobe globe, ESRI.ArcGIS.Carto.ILayer layer, int featureID)
{
  ESRI.ArcGIS.GlobeCore.IGlobeDisplay globeDisplay=globe.GlobeDisplay;
  ESRI.ArcGIS.Analyst3D.IScene scene=globeDisplay.Scene;

  // Get a handle to the animation extension
  ESRI.ArcGIS.Analyst3D.IBasicScene2 basicScene2=(ESRI.ArcGIS.Analyst3D.IBasicScene2)scene; // Explicit Cast
  ESRI.ArcGIS.Animation.IAnimationExtension animationExtension=basicScene2.AnimationExtension;

  ESRI.ArcGIS.Carto.IFeatureLayer featureLayer=(ESRI.ArcGIS.Carto.IFeatureLayer)layer; // Explicit Cast
  ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass=featureLayer.FeatureClass;
  ESRI.ArcGIS.Geodatabase.IFeature feature=featureClass.GetFeature(featureID);

  // Get the geometry of the line feature
  ESRI.ArcGIS.Geometry.IGeometry geometry=feature.Shape;

  // Create AGAnimationUtils and AGImportPathOptions objects
  ESRI.ArcGIS.Animation.IAGAnimationUtils agAnimationUtils=new ESRI.ArcGIS.Animation.AGAnimationUtilsClass();
  ESRI.ArcGIS.Animation.IAGImportPathOptions agImportPathOptions=new ESRI.ArcGIS.Animation.AGImportPathOptionsClass();

  // Set properties for AGImportPathOptions
  agImportPathOptions.BasicMap=(ESRI.ArcGIS.Carto.IBasicMap)globe; // Explicit Cast
  agImportPathOptions.AnimationTracks=(ESRI.ArcGIS.Animation.IAGAnimationTracks)globe; // Explicit Cast
  agImportPathOptions.AnimationType=new ESRI.ArcGIS.GlobeCore.AnimationTypeGlobeCameraClass();
  agImportPathOptions.AnimatedObject=globe.GlobeDisplay.ActiveViewer.Camera;
  agImportPathOptions.PathGeometry=geometry;
  agImportPathOptions.ConversionType=ESRI.ArcGIS.Animation.esriFlyFromPathType.esriFlyFromPathObsAndTarget;
  agImportPathOptions.LookaheadFactor=0.05;
  agImportPathOptions.RollFactor=0;

  agImportPathOptions.AnimationEnvironment=animationExtension.AnimationEnvironment;
  ESRI.ArcGIS.Animation.IAGAnimationContainer AGAnimationContainer=animationExtension.AnimationTracks.AnimationObjectContainer;

  // Call "CreateFlybyFromPath"
  agAnimationUtils.CreateFlybyFromPath(AGAnimationContainer, agImportPathOptions);
}
[Visual Basic .NET]
'''<summary>Creates a camera animation from path. The path is supplied by specifying a specific line feature from a ILayer.</summary>
''' 
'''<param name="globe">An IGlobe interface</param>
'''<param name="layer">An ILayer interface that is a Polyline</param>
'''<param name="featureID">A System.Int32 that is the FeatureID record number for which the fly by is to follow to create the animation. Example: 123</param>
'''  
'''<remarks></remarks>
Public Sub CreateAnimationFromPath(ByVal globe As ESRI.ArcGIS.GlobeCore.IGlobe, ByVal layer As ESRI.ArcGIS.Carto.ILayer, ByVal featureID As System.Int32)

  Dim globeDisplay As ESRI.ArcGIS.GlobeCore.IGlobeDisplay=globe.GlobeDisplay
  Dim scene As ESRI.ArcGIS.Analyst3D.IScene=globeDisplay.Scene

  ' Get a handle to the animation extension
  Dim basicScene2 As ESRI.ArcGIS.Analyst3D.IBasicScene2=CType(scene, ESRI.ArcGIS.Analyst3D.IBasicScene2) ' Explicit Cast
  Dim animationExtension As ESRI.ArcGIS.Animation.IAnimationExtension=basicScene2.AnimationExtension

  Dim featureLayer As ESRI.ArcGIS.Carto.IFeatureLayer=CType(layer, ESRI.ArcGIS.Carto.IFeatureLayer) ' Explicit Cast
  Dim featureClass As ESRI.ArcGIS.Geodatabase.IFeatureClass=featureLayer.FeatureClass
  Dim feature As ESRI.ArcGIS.Geodatabase.IFeature=featureClass.GetFeature(featureID)

  ' Get the geometry of the line feature
  Dim geometry As ESRI.ArcGIS.Geometry.IGeometry=feature.Shape

  ' Create AGAnimationUtils and AGImportPathOptions objects
  Dim AGAnimationUtils As ESRI.ArcGIS.Animation.IAGAnimationUtils=New ESRI.ArcGIS.Animation.AGAnimationUtilsClass
  Dim AGImportPathOptions As ESRI.ArcGIS.Animation.IAGImportPathOptions=New ESRI.ArcGIS.Animation.AGImportPathOptionsClass

  ' Set properties for AGImportPathOptions
  AGImportPathOptions.BasicMap=CType(globe, ESRI.ArcGIS.Carto.IBasicMap) ' Explicit Cast
  AGImportPathOptions.AnimationTracks=CType(globe, ESRI.ArcGIS.Animation.IAGAnimationTracks) ' Explicit Cast
  AGImportPathOptions.AnimationType=New ESRI.ArcGIS.GlobeCore.AnimationTypeGlobeCameraClass
  AGImportPathOptions.AnimatedObject=globe.GlobeDisplay.ActiveViewer.Camera
  AGImportPathOptions.PathGeometry=geometry
  AGImportPathOptions.ConversionType=ESRI.ArcGIS.Animation.esriFlyFromPathType.esriFlyFromPathObsAndTarget
  AGImportPathOptions.LookaheadFactor=0.05
  AGImportPathOptions.RollFactor=0

  AGImportPathOptions.AnimationEnvironment=animationExtension.AnimationEnvironment
  Dim AGAnimationContainer As ESRI.ArcGIS.Animation.IAGAnimationContainer=animationExtension.AnimationTracks.AnimationObjectContainer

  ' Call "CreateFlybyFromPath"
  AGAnimationUtils.CreateFlybyFromPath(AGAnimationContainer, AGImportPathOptions)

End Sub

Additional Requirements
  • The code in this document requires the following References added to the Visual Studio project:
  • ESRI.ArcGIS.3DAnalyst
  • ESRI.ArcGIS.Animation
  • ESRI.ArcGIS.Carto
  • ESRI.ArcGIS.Display
  • ESRI.ArcGIS.Geodatabase
  • ESRI.ArcGIS.Geometry
  • ESRI.ArcGIS.GlobeCore