CreateLayoutPaneAsync Method
Create and activate a new layout pane using a Layout reference. Must be called on GUI thread.
CreateLayout_WITH_WD_AND_HT
//This example creates a new layout using a minimum set of parameters.
//Added references
using ArcGIS.Desktop.Layouts;
using ArcGIS.Desktop.Framework.Threading.Tasks;
using ArcGIS.Desktop.Core;
public class CreateLayoutEx1
{
async public static Task<Layout> CreateBasicLayout(double width, double height, LinearUnit units, string LayoutName)
{
Layout layout = null;
await QueuedTask.Run(() =>
{
layout = LayoutFactory.Instance.CreateLayout(width, height, units);
layout.SetName(LayoutName);
});
//Open the layout in a pane on the UI!
await ProApp.Panes.CreateLayoutPaneAsync(layout);
return layout;
}
}
CreateLayout_With_CIMPAGE
//This example creates a new layout using a CIM page definion with rulers and guides included.
//Added references
using ArcGIS.Desktop.Layouts;
using ArcGIS.Desktop.Framework.Threading.Tasks;
using ArcGIS.Desktop.Core;
using ArcGIS.Core.CIM;
public class CreateLayoutEx2
{
async public static Task<Layout> CreateCIMLayout(double width, double height, LinearUnit units, string LayoutName)
{
Layout CIMlayout = null;
await QueuedTask.Run(() =>
{
//Set up a page
CIMPage newPage = new CIMPage();
//required
newPage.Width = width;
newPage.Height = height;
newPage.Units = units;
//optional rulers
newPage.ShowRulers = true;
newPage.SmallestRulerDivision = 5;
//optional guides
newPage.ShowGuides = true;
CIMGuide guide1 = new CIMGuide();
guide1.Position = 25;
guide1.Orientation = Orientation.Vertical;
CIMGuide guide2 = new CIMGuide();
guide2.Position = 185;
guide2.Orientation = Orientation.Vertical;
CIMGuide guide3 = new CIMGuide();
guide3.Position = 25;
guide3.Orientation = Orientation.Horizontal;
CIMGuide guide4 = new CIMGuide();
guide4.Position = 272;
guide4.Orientation = Orientation.Horizontal;
List<CIMGuide> guideList = new List<CIMGuide>();
guideList.Add(guide1);
guideList.Add(guide2);
guideList.Add(guide3);
guideList.Add(guide4);
newPage.Guides = guideList.ToArray();
Layout layout = LayoutFactory.Instance.CreateLayout(newPage);
layout.SetName(LayoutName);
});
//Open the layout in a pane on the UI!
await ProApp.Panes.CreateLayoutPaneAsync(CIMlayout);
return CIMlayout;
}
}
LayoutView_LayoutFrameWorkExtender
//This sample checks to see if a layout project item already has an open application pane.
//If it does, it checks if it is the active layout view, if not, it creates, activates and opens a new pane.
//Reference a layoutitem in a project by name
LayoutProjectItem layoutItem = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals("Layout View"));
//Get the layout associated with the layoutitem
Layout lyt = await QueuedTask.Run(() => layoutItem.GetLayout());
//Iterate through each pane in the application and check to see if the layout is already open and if so, activate it
foreach (var pane in ProApp.Panes)
{
var layoutPane = pane as ILayoutPane;
if (layoutPane == null) //if not a layout pane, continue to the next pane
continue;
if (layoutPane.LayoutView.Layout == lyt) //if the layout pane does match the layout, activate it.
{
(layoutPane as Pane).Activate();
layoutPane.Caption = "This is a test";
System.Windows.MessageBox.Show(layoutPane.Caption);
return;
}
}
//Otherwise, create, open, and activate the layout if not already open
ILayoutPane newPane = await ProApp.Panes.CreateLayoutPaneAsync(lyt);
//Zoom to the full extent of the layout
await QueuedTask.Run(() => newPane.LayoutView.ZoomTo100Percent());
Open a layout project item in a new view
//Open a layout project item in a new view.
//A layout project item may exist but it may not be open in a view.
//Reference a layout project item by name
LayoutProjectItem someLytItem = Project.Current.GetItems<LayoutProjectItem>()
.FirstOrDefault(item => item.Name.Equals("MyLayout"));
//Get the layout associated with the layout project item
Layout layout = await QueuedTask.Run(() => someLytItem.GetLayout()); //Worker thread
//Create the new pane - call on UI
ILayoutPane iNewLayoutPane = await ProApp.Panes.CreateLayoutPaneAsync(layout); //GUI thread
Create a new, basic layout and open it
//Create a new, basic layout and open it.
//Create layout with minimum set of parameters on the worker thread
Layout lyt = await QueuedTask.Run(() =>
{
var newLayout = LayoutFactory.Instance.CreateLayout(8.5, 11, LinearUnit.Inches);
newLayout.SetName("New 8.5x11 Layout");
return newLayout;
});
//Open new layout on the GUI thread
await ProApp.Panes.CreateLayoutPaneAsync(lyt);
Create a new layout using a modified CIM and open it
//Create a new layout using a modified CIM and open it.
//The CIM exposes additional members that may not be
//available through the managed API.
//In this example, optional guides are added.
//Create a new CIMLayout on the worker thread
Layout newCIMLayout = await QueuedTask.Run(() =>
{
//Set up a CIM page
CIMPage newPage = new CIMPage
{
//required parameters
Width = 8.5,
Height = 11,
Units = LinearUnit.Inches,
//optional rulers
ShowRulers = true,
SmallestRulerDivision = 0.5,
//optional guides
ShowGuides = true
};
CIMGuide guide1 = new CIMGuide
{
Position = 1,
Orientation = Orientation.Vertical
};
CIMGuide guide2 = new CIMGuide
{
Position = 6.5,
Orientation = Orientation.Vertical
};
CIMGuide guide3 = new CIMGuide
{
Position = 1,
Orientation = Orientation.Horizontal
};
CIMGuide guide4 = new CIMGuide
{
Position = 10,
Orientation = Orientation.Horizontal
};
List<CIMGuide> guideList = new List<CIMGuide>
{
guide1,
guide2,
guide3,
guide4
};
newPage.Guides = guideList.ToArray();
//Construct the new layout using the customized cim definitions
var layout_local = LayoutFactory.Instance.CreateLayout(newPage);
layout_local.SetName("New 8.5x11 Layout");
return layout_local;
});
//Open new layout on the GUI thread
await ProApp.Panes.CreateLayoutPaneAsync(newCIMLayout);
Target Platforms: Windows 11, Windows 10
ArcGIS Pro version: 3 or higher.