Creating a Presentation

This example demonstrates how to retrieve an existing presentation object, extract its JSON definition, modify its contents, and then apply the updated JSON to a new presentation using the IPresentation.PresentationJSON property. Instead of building a presentation definition entirely from scratch, this approach lets you start from a working presentation created in TerraExplorer, adjust only the relevant parts (for example, add a new action or edit parameters), and then generate a new presentation with the modified JSON. This method is often easier and more reliable than constructing the full JSON manually from the presentation schema.

using Newtonsoft.Json;

using Newtonsoft.Json.Linq;

using TerraExplorerX;

 

try

            {

                // Get existing presentation by name

                string itemId = SGWorld.ProjectTree.FindItem(" Auburn - Fireworks & Water Body");

                IPresentation81 oldPresentation = (IPresentation81)SGWorld.ProjectTree.GetObject(itemId);

               

                // Parse existing presentation JSON into JObject

                JObject json = JObject.Parse(oldPresentation.PresentationJSON);

 

                // Create new FlyTo action as JObject

                JObject actionFlyTo = newJObject

                {

                    ["actionType"] = "FlyTo",

                    ["description"] = "",

                    ["options"] = new JObject

                    {

                        ["activationAction"] = "Circle pattern",

                        ["duration"] = 5,

                        ["poi"] = new JObject

                        {

                            ["altitude"] = 1494.09375,

                            ["distance"] = 3877278.555371787,

                            ["isRelative"] = false,

                            ["viewerPitch"] = -72.06956713327715,

                            ["viewerYaw"] = 355.4828574744612,

                            ["x"] = -103.95114771762604,

                            ["y"] = 35.60232149209262

                        }

                    }

                };

 

                // Append the new action to the first step in the presentation

                JArray actions = (JArray)json["presentation"]["steps"][0]["actions"];

                actions.Add(actionFlyTo);

 

                // Create a new presentation object

                varnewPresentation = SGWorld.Creator.CreatePresentation("", "New Presentation C#");

 

                // Assign updated JSON back to the new presentation

                newPresentation.PresentationJSON = json.ToString(Formatting.None);

            }

            catch (Exception ex)

            {

                System.Windows.Forms.MessageBox.Show(ex.ToString(), "Error");

            }

 

 

 

 

using Newtonsoft.Json.Linq;

 

private void CreatePresentation(objectsender, EventArgs e)

{

    // Build the JSON structure as JObject

    var JSONString = new JObject

    {

        ["presentation"] = new JObject

        {

            ["bookmark"] = false,

            ["description"] = "Auburn - Fireworks & Water Body",

            ["id"] = "0_67116",

            ["settings"] = new JObject

            {

                ["interpolation"] = 1.0,

                ["loopPresentation"] = false,

                ["playSpeedFactor"] = 1.0,

                ["unattendedPlayMode"] = false

            },

            ["stepRequireClick"] = true,

            ["steps"] = new JArray

            {

                new JObject

                {

                    ["actions"] = new JArray

                    {

                        newJObject

                        {

                            ["actionType"] = "Click",

                            ["description"] = "",

                            ["id"] = "dbbc034d-920c-44f1-0619-2c61a8f9d7cc",

                            ["options"] = new JObject()

                        },

                        newJObject

                        {

                            ["actionType"] = "DynamicObject",

                            ["description"] = "Restart Dynamic Object: Bell 206",

                            ["id"] = "fa71ab49-439a-3404-91a8-7f74412c1164",

                            ["options"] = new JObject

                            {

                                ["TeObjectId"] = "0_18204",

                                ["operation"] = "Restart"

                            }

                        },

                        newJObject

                        {

                            ["actionType"] = "Show",

                            ["description"] = "Show Auburn ©Dat’Air",

                            ["id"] = "9625970e-0020-19a4-228b-966f160de87a",

                            ["options"] = new JObject

                            {

                                ["pathToGroup"] = "3D City Models\\Auburn ©Dat’Air"

                            }

                        },

                        newJObject

                        {

                            ["actionType"] = "FlyTo",

                            ["description"] = "Fly to: [-85.4909, 32.6019]",

                            ["id"] = "4c6441f2-5c03-5abf-26ec-2316becdbd42",

                            ["options"] = new JObject

                            {

                                ["activationAction"] = "Fly To",

                                ["poi"] = new JObject

                                {

                                    ["altitude"] = 193.977051,

                                    ["distance"] = 893.916501,

                                    ["isRelative"] = false,

                                    ["viewerPitch"] = -37.519739,

                                    ["viewerYaw"] = 318.002710,

                                    ["x"] = -85.490920,

                                    ["y"] = 32.601869

                                },

                                ["splineSpeedFunction"] = 0,

                                ["splineTurnSpeedFunction"] = 0

                            }

                        },

                        newJObject

                        {

                            ["actionType"] = "Caption",

                            ["description"] = "Caption: Auburn AL - Resolution: 5cm (Dat'Air Inc.)",

                            ["id"] = "f2e85651-0c7f-2c50-6640-e4a4a4c230dd",

                            ["options"] = new JObject

                            {

                                ["LastKnownCaption"] = "",

                                ["RTL"] = false,

                                ["backgroundColor"] = 0,

                                ["backgroundColorAlpha"] = 0,

                                ["captionHeight"] = 20,

                                ["captionText"] = "Auburn AL - Resolution: 5cm (Dat'Air Inc.)",

                                ["captionWidth"] = 300,

                                ["fontBold"] = false,

                                ["fontColor"] = 0,

                                ["fontColorAlpha"] = 1,

                                ["fontSize"] = 14,

                                ["position"] = 4,

                                ["timeOutInterval"] = -1,

                                ["transparent"] = false

                            }

                        },

                        newJObject

                        {

                            ["actionType"] = "Wait",

                            ["description"] = "Wait: 10 sec.",

                            ["id"] = "1dc2006e-866f-8e6f-3a7d-759de3d7b07b",

                            ["options"] = new JObject

                            {

                                ["duration"] = 10

                            }

                        },

                        newJObject

                        {

                            ["actionType"] = "Caption",

                            ["description"] = "Clear caption",

                            ["id"] = "a76da174-2362-b7a3-582d-6fbb1b3cdb79",

                            ["options"] = new JObject

                            {

                                ["LastKnownCaption"] = "",

                                ["RTL"] = false,

                                ["backgroundColor"] = 0,

                                ["backgroundColorAlpha"] = 0,

                                ["captionHeight"] = 20,

                                ["captionText"] = "",

                                ["captionWidth"] = 300,

                                ["fontBold"] = false,

                                ["fontColor"] = 0,

                                ["fontColorAlpha"] = 1,

                                ["fontSize"] = 14,

                                ["position"] = 4,

                                ["timeOutInterval"] = -2,

                                ["transparent"] = false

                            }

                        },

                        newJObject

                        {

                            ["actionType"] = "Caption",

                            ["description"] = "Caption: Fireworks Animation Effects",

                            ["id"] = "3bbff5a7-cd32-b17a-ef6d-fc009b1a00ae",

                            ["options"] = new JObject

                            {

                                ["LastKnownCaption"] = "",

                                ["RTL"] = false,

                                ["backgroundColor"] = 0,

                                ["backgroundColorAlpha"] = 0,

                                ["captionHeight"] = 20,

                                ["captionText"] = "Fireworks Animation Effects",

                                ["captionWidth"] = 300,

                                ["fontBold"] = false,

                                ["fontColor"] = 0,

                                ["fontColorAlpha"] = 1,

                                ["fontSize"] = 14,

                                ["position"] = 4,

                                ["timeOutInterval"] = -1,

                                ["transparent"] = false

                            }

                        },

                        newJObject

                        {

                            ["actionType"] = "Show",

                            ["description"] = "Show Auburn",

                            ["id"] = "892e4881-f1d7-b896-4401-e4efcad71074",

                            ["options"] = new JObject

                            {

                                ["pathToGroup"] = "3D City Models\\Effects\\Auburn"

                            }

                        },

                        newJObject

                        {

                            ["actionType"] = "Wait",

                            ["description"] = "Wait: 5 sec.",

                            ["id"] = "3f2b7fdd-f07d-553e-989b-136aee205d51",

                            ["options"] = new JObject

                            {

                                ["duration"] = 5

                            }

                        },

                        newJObject

                        {

                            ["actionType"] = "Caption",

                            ["description"] = "Clear caption",

                            ["id"] = "55d8f9fb-c45c-f8ae-b1db-a47a9851a315",

                            ["options"] = new JObject

                            {

                                ["LastKnownCaption"] = "",

                                ["RTL"] = false,

                                ["backgroundColor"] = 0,

                                ["backgroundColorAlpha"] = 0,

                                ["captionHeight"] = 20,

                                ["captionText"] = "",

                                ["captionWidth"] = 300,

                                ["fontBold"] = false,

                                ["fontColor"] = 0,

                                ["fontColorAlpha"] = 1,

                                ["fontSize"] = 14,

                                ["position"] = 4,

                                ["timeOutInterval"] = -2,

                                ["transparent"] = false

                            }

                        }

                    },

                    ["bookmark"] = false,

                    ["description"] = "Step",

                    ["id"] = "d041c54c-4fa3-99b2-dda1-a9f38be5c241",

                    ["stepRequireClick"] = true

                }

            }

        }

    };

 

    // Convert JObject to a compact JSON string

    string json = JSONString.ToString(Newtonsoft.Json.Formatting.None);

 

    // Create the presentation in TerraExplorer

    var newPresFromJSON = SGWorld.Creator.CreatePresentation("", "newPresFromJSON");

 

    // Assign the JSON to PresentationJSON property

    newPresFromJSON.PresentationJSON = json;

}