how to set active layout

142
2
05-24-2019 07:56 AM
WuYao
by
New Contributor

I have a list of layouts and want to be able to set one of them as the active view in Pro SDK

0 Kudos
2 Replies
JeffBarrette
Esri Regular Contributor

Please check out Layout snippets 2-4: https://github.com/esri/arcgis-pro-sdk/wiki/ProSnippets-Layouts

Here is a code snippet of mine that looks for all possibilities (examples above combined):

//Check to see if the layout already exists
LayoutProjectItem layoutItem = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals("Game Board"));
if (layoutItem != null)
{
Layout lyt = await QueuedTask.Run(() => layoutItem.GetLayout());

//Next check to see if a layout view is already open that referencs the Game Board layout
foreach (var pane in ProApp.Panes)
{
var lytPane = pane as ILayoutPane;
if (lytPane == null) //if not a layout view, continue to the next pane
continue;
if (lytPane.LayoutView.Layout == lyt) //if there is a match, activate the view
{
(lytPane as Pane).Activate();
System.Windows.MessageBox.Show("Activating existing pane");
return;
}
}

//If panes don't exist, then open a new pane
await ProApp.Panes.CreateLayoutPaneAsync(lyt);
System.Windows.MessageBox.Show("Opening already existing layout");
return;
}

//The layout does not exist so create a new one
Layout layout = await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run<Layout>(() =>
{
//*** CREATE A NEW LAYOUT ***

0 Kudos
WuYao
by
New Contributor

Thank you Jeff!

0 Kudos