This tutorial demonstrates how to add ArcGIS Pro playback controls to your add-in to start and stop your animation. It also shows how to use a combobox to enter camera roll values, which are used to create of new keyframes in a 3D animation.
With the ArcGIS Pro SDK for .NET, you can extend ArcGIS Pro with your own unique tools and workflows. Using Microsoft Visual Studio and the Pro SDK, developers can build Pro add-ins and solution configurations that provide users with custom functionality specific to their organization or industry.
The ArcGIS Pro SDK for .NET provides a Map Exploration API, which allows you to create keyframes that can store values using the camera
class.
In this tutorial, you will create a fly-through animation that allows you to pause playback, and insert new keyframes with roll values that bank / tilt the camera, providing a more interesting animation and demonstrating control using the SDK.
Prerequisites
- Microsoft Visual Studio is required. See the ArcGIS Pro system requirements for latest version and compatibility.
- Install ArcGIS Pro version 3.3 or higher.
- Install the ArcGIS Pro SDK for .NET. See the Installation ProGuide for more information.
- This tutorial uses Pro SDK Community sample data.
Steps
Before you begin
Take some time to review the ArcGIS Pro documentation on animating the camera and on the Keyframe List.
Create a new animation and keyframes using a sample dataset
-
Start ArcGIS Pro. When the start page appears, select the previously-installed Pro sample project:
C
.:\ Data\ Interacting with Maps\ Interacting with Maps.aprx -
When the project opens, open the Catalog pane (View > Catalog Pane).
-
On the pane, open the Maps > Portland 3D City scene.
-
In the TOC, in the 3D Layers section, right-click on the Buildings layer and select Zoom to Layer. From here you will begin to build a series of animation keyframes to be used by your add-in.
-
Click the View tab. In the Animation group, select Add. The Animation Timeline pane should display with a Create first keyframe button.
-
Click Create first keyframe to create your first keyframe. Each time you create a keyframe, you store the current map view.
-
Zoom closer into the scene buildings and change your perspective (use the 3D navigator if needed), and then use the + button to add approximately five additional keyframes with different views simulating a fly-through around the buildings. By default, each keyframe you add will be given a 3-second time gap.
-
In the Keyframe Gallery > Animation Timeline, click on your first keyframe and then press Autoplay forward below the timeline to try out the fly-through with the keyframes you created.
-
Save your project with your new keyframes, and close ArcGIS Pro. You are now ready to build your add-in, which uses the fly-through animation you just created.
Create a new ArcGIS Pro Add-In Visual Studio Project
-
Start Visual Studio.
-
Choose File > New > Project and then from the ArcGIS templates group, select ArcGIS Pro Module Add-in. Name the add-in project
Camera
.Properties By default, the
Config.daml
file opens in Visual Studio. TheModule1.cs
file contains add-in module code.Note also in the
Config.daml
file that theid
attribute of theinsert
tag matches the ID within theModule Module1.cs
file and theclass
attribute matches the class name of the module.Name The ArcGIS templates group is located in Templates > Visual C# > ArcGIS. Confirm that the latest .NET Framework is selected.
Add Ribbon controls to your add-in
-
Right-click the project and choose Add > New Item. From the ArcGIS Pro Add-ins group, select ArcGIS Pro Button from the list of item templates.
-
When prompted, name the new class file
Create
and click Add to close the dialog box. The Button template provides the contents of the class file, as well as the corresponding code in theKeyframe.cs Config.daml
file for the Pro UI. -
Right-click the project and choose Add > New Item again. From the ArcGIS Pro Add-ins group, select ArcGIS Pro ComboBox from the list of item templates.
-
When prompted, name the new class file
Roll
and click Add to close the dialog box. The ComboBox template also provides the contents of the class file, as well as the corresponding code in theVal Combobox.cs Config.daml
file for ArcGIS Pro UI.
Update code in the Config.daml
and Module1.cs
files
-
Open the
Config.daml
file and replace the contents of the groups and controls sections with the following:This DAML code provides the following:
-
Adds animation playback control, named Keyframe Tools Sample, to your new controls group.
-
Updates the captions and sizes of the button and combobox controls in the group.
-
Enables editing of your combobox control.
Use dark colors for code blocks Copy <groups> <group id="CameraProperties_Group1" caption="Keyframe Tools Sample" appearsOnAddInTab="true"> <button refID="esri_mapping_animationPlaybackControl" /> <comboBox refID="CameraProperties_RollValCombobox" size="middle" /> <button refID="CameraProperties_CreateKeyframe" size="middle" /> </group> </groups> <controls> <button id="CameraProperties_CreateKeyframe" caption="Create Keyframe with roll value" className="CreateKeyframe" loadOnClick="true" smallImage="pack://application:,,,/ArcGIS.Desktop.Resources;component/Images/GenericButtonBlue16.png" largeImage="pack://application:,,,/ArcGIS.Desktop.Resources;component/Images/GenericButtonBlue32.png"> <tooltip heading="Tooltip Heading">Tooltip text<disabledText /></tooltip> </button> <comboBox id="CameraProperties_RollValCombobox" caption="Enter roll value:" className="RollValCombobox" itemWidth="140" extendedCaption="Extended Caption" isEditable="true" isReadOnly="false" resizable="true"> <tooltip heading="Tooltip Heading">Tooltip text<disabledText /></tooltip> </comboBox> </controls>
-
-
Open the
Module1.cs
file and paste the following code below theOverrides
region:It is helpful to consolidate business logic in the module when possible. This new code provides the following:
-
Creates an instance of the
Roll
for use in the module.Val Combobox -
Creates a new method,
Create
, to be called by the button. This new method:New Key Frame - Gets the current animations, camera and camera track.
- Gets the current value in the roll value combobox.
- Creates a new keyframe with the roll value if a valid numeric value is entered into the combobox.
- Notifies the user if an invalid value is in the combobox.
Use dark colors for code blocks Copy #region Business Logic public RollValCombobox RollValueCombobox { get; set; } public void CreateNewKeyFrame() { QueuedTask.Run(() => { var currentmapview = MapView.Active; var currentcamera = currentmapview.Camera; var newCamera = currentcamera; var viewAnimation = currentmapview.Animation; var currentAnimationTime = viewAnimation.CurrentTime; var mapAnimation = currentmapview.Map.Animation; var cameraTrack = mapAnimation.Tracks.OfType<CameraTrack>().First(); // Check the entered roll value and if valid, create a keyframe using it. var rollValue = RollValueCombobox.Text; if (Double.TryParse(rollValue, out double dblRollValue)) { newCamera.Roll = dblRollValue; cameraTrack.CreateKeyframe(newCamera, currentAnimationTime, AnimationTransition.Linear); } else { ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Roll value can't be used, please re-enter a valid number."); RollValueCombobox.Text = ""; } }); } #endregion
-
Update button and combobox code
-
Open the
Create
file and go to theKeyframe.cs On
method. Add the following code:Click Module1.
Your code, located below the using statements, should look like the following:Current. Create New Key Frame(); When clicked, this button will call the
Create
method inNew Key Frame Module1
.Use dark colors for code blocks Copy namespace CameraProperties { internal class CreateKeyframe : Button { protected override void OnClick() { Module1.Current.CreateNewKeyFrame(); } } }
-
Open the
Roll
file and replaceVal Combobox.cs Update
with the following code:Combo() Module1.
Your code for the constructor should look like the following:Current. Roll Value Combobox = this; This allows
Module1
to reference an instance of this class. No other code changes are needed in this file.Use dark colors for code blocks Copy public RollValCombobox() { Module1.Current.RollValueCombobox = this; }
Build and test your code
-
Once your code is complete, build your project and debug any issues. Click Start to launch ArcGIS Pro. Open the Interacting with Maps project that you updated with your new animation in Create a new animation and keyframes using a sample dataset.
-
Open the Animation Timeline pane (if not already open) and ensure that you have created at least five keyframes. Select the first keyframe in the Keyframe Gallery, which sets playback to the beginning of the animation. Next, go to the Add-In tab, and find your add-in’s new Keyframe Tools Sample group, which should contain the animation playback controls, a combobox, and a button.
-
Press Play on the playback controls, which begins the fly-through animation. As you get to a location between your existing keyframes, pause the animation with the playback control. You will now create a new keyframe.
-
Add a numeric value for the degrees of roll into your add-in’s combobox (e.g., 45). A positive value will roll/tilt the camera to the right, and a negative value rolls to the left. Once you enter the value, press the button below it to create the keyframe. You should see the new keyframe created and added to the Timeline and Keyframe Gallery between your existing keyframes. Press Play again, and along the timeline create another new keyframe, this time with a negative roll value (e.g., -45)
-
Play through your animation again, and you should see your new keyframes applied with the camera roll property and visualization. You can also open the Animation Properties pane and view the camera properties as the change during playback.
What's Next?
Learn how to use additional ArcGIS Pro SDK for .NET features in these tutorials: