Is there a way to open an existing layout programmatically?

2049
3
07-30-2015 06:18 AM
Highlighted
New Contributor III

From the layout snippets and examples provided I understand how to get a reference to an existing layout, but is there a way to also open it programmatically? 

Reply
0 Kudos
3 Replies
Highlighted
Esri Regular Contributor

There is currently not a way to open a layout yet but there will be.

Highlighted
New Contributor III

Will there be a way to obtain the existing layouts much like the way we can retrieve layers?

Example:
MapView activeView = MapView.Active;

IReadOnlyList<Layer> allMapLayers = activeView.Map.GetLayersAsFlattenedList();

Project project = Project.Current;

IReadOnlyList<Layout> allLayouts = project.GetLayoutsAsFlattenedList();

OR

IReadOnlyList<LayoutProjectItem> allLayouts = project.GetLayoutItemsAsFlattenedList();

Reply
0 Kudos
Highlighted
Esri Contributor

FYI: You will need to add a reference to ArcGIS.Desktop.Layouts.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using ArcGIS.Desktop.Core;

using ArcGIS.Desktop.Framework;

using ArcGIS.Desktop.Framework.Contracts;

using ArcGIS.Desktop.Framework.Dialogs;

using ArcGIS.Desktop.Framework.Threading.Tasks;

using ArcGIS.Desktop.Layouts; <-- add the ArcGIS.Desktop.Layouts.dll to your references

namespace ProAppModule4 {

    internal class Button1 : Button {

        protected async override void OnClick() {

            var layouts = Project.Current.GetItems<LayoutProjectItem>();

            StringBuilder sb = new StringBuilder();

            sb.AppendLine("Layouts:");

            await QueuedTask.Run(() => {

                foreach (var layoutItem in layouts) {

                    var layout = layoutItem.GetLayout();

                    sb.AppendLine(string.Format("\t{0}", layout.Name));

                    //etc

                }

            });

            MessageBox.Show(sb.ToString());

        }

    }

}

Reply
0 Kudos