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?
There is currently not a way to open a layout yet but there will be.
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();
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());
}
}
}