Select to view content in your preferred language

Is there a way to open an existing layout programmatically?

2569
3
07-30-2015 06:18 AM
AnthonyMikelson
Occasional Contributor

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? 

0 Kudos
3 Replies
JeffBarrette
Esri Regular Contributor

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

AnthonyMikelson
Occasional Contributor

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();

0 Kudos
CharlesMacleod
Esri Regular 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());

        }

    }

}

0 Kudos