//Reference layout project items and their associated layout.
//A layout project item is an item that appears in the Layouts folder in the Catalog pane.
//Reference all the layout project items
IEnumerable<LayoutProjectItem> layouts = Project.Current.GetItems<LayoutProjectItem>();
//Or reference a specific layout project item by name
LayoutProjectItem layoutItem = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals("MyLayout"));
//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
ILayoutPane iNewLayoutPane = await ProApp.Panes.CreateLayoutPaneAsync(layout); //GUI thread
//Import a pagx into a project.
//Create a layout project item from importing a pagx file
IProjectItem pagx = ItemFactory.Instance.Create(@"C:\Temp\Layout.pagx") as IProjectItem;
Project.Current.AddItem(pagx);
//This example deletes a layout in a project after finding it by name.
//Added references
using ArcGIS.Desktop.Core;
using ArcGIS.Desktop.Layouts;
public class DeleteLayoutExample
{
public static Task<bool> DeleteLayoutAsync(string LayoutName)
{
//Reference a layoutitem in a project by name
LayoutProjectItem layoutItem = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals(LayoutName));
//Check for layoutItem
if (layoutItem == null)
return Task.FromResult<bool>(false);
//Delete the layout from the project
return Task.FromResult<bool>(Project.Current.RemoveItem(layoutItem));
}
}