GetItems<T> Method (Project)
Get MapProjectItems
/// Get all the maps in a project
IEnumerable<MapProjectItem> projectMaps = Project.Current.GetItems<MapProjectItem>();
Get FolderConnectionProjectItems
/// Get all the folder connections in a project
IEnumerable<FolderConnectionProjectItem> projectFolders = Project.Current.GetItems<FolderConnectionProjectItem>();
Get ServerConnectionProjectItems
/// Get all the server connections in a project
IEnumerable<ServerConnectionProjectItem> projectServers = Project.Current.GetItems<ServerConnectionProjectItem>();
Get LocatorConnectionProjectItems
/// Get all the locator connections in a project
IEnumerable<LocatorsConnectionProjectItem> projectLocators = Project.Current.GetItems<LocatorsConnectionProjectItem>();
Get Project Items by ProjectItem type
/// Get all the items that can be accessed from a folder connection. The items immediately
/// contained by a folder, that is, the folder's children, are returned including folders
/// and individual items that can be used in ArcGIS Pro. This method does not return all
/// items contained by any sub-folder that can be accessed from the folder connection.
FolderConnectionProjectItem folderConnection = Project.Current.GetItems<FolderConnectionProjectItem>()
.FirstOrDefault((folder => folder.Name.Equals("Data")));
await QueuedTask.Run(() =>
{
IEnumerable<Item> folderContents = folderConnection.GetItems();
});
Get Folder Item Content from Project PortalItem
var folderConnectionContent = projectfolderConnection.GetItems();
var folder = folderConnectionContent.FirstOrDefault(folderItem => folderItem.Name.Equals("Tourist Sites"));
var folderContents = folder.GetItems();
Get all project items
IEnumerable<Item> allProjectItems = Project.Current.GetItems<Item>();
foreach (var pi in allProjectItems)
{
//Do Something
}
Get all "MapProjectItems" for a project
IEnumerable<MapProjectItem> newMapItemsContainer = project.GetItems<MapProjectItem>();
await QueuedTask.Run(() =>
{
foreach (var mp in newMapItemsContainer)
{
//Do Something with the map. For Example:
Map myMap = mp.GetMap();
}
});
Get a specific "MapProjectItem"
MapProjectItem mapProjItem = Project.Current.GetItems<MapProjectItem>().FirstOrDefault(item => item.Name.Equals("EuropeMap"));
Get all "StyleProjectItems"
IEnumerable<StyleProjectItem> newStyleItemsContainer = null;
newStyleItemsContainer = Project.Current.GetItems<StyleProjectItem>();
foreach (var styleItem in newStyleItemsContainer)
{
//Do Something with the style.
}
Get a specific "StyleProjectItem"
var container = Project.Current.GetItems<StyleProjectItem>();
StyleProjectItem testStyle = container.FirstOrDefault(style => (style.Name == "ArcGIS 3D"));
StyleItem cone = null;
if (testStyle != null)
cone = testStyle.LookupItem(StyleItemType.PointSymbol, "Cone_Volume_3");
Get the "Favorite" StyleProjectItem
var fav_style_item = await QueuedTask.Run(() =>
{
var containerStyle = Project.Current.GetProjectItemContainer("Style");
return containerStyle.GetItems().OfType<StyleProjectItem>().First(item => item.TypeID == "personal_style");
});
Get all "GDBProjectItems"
IEnumerable<GDBProjectItem> newGDBItemsContainer = null;
newGDBItemsContainer = Project.Current.GetItems<GDBProjectItem>();
foreach (var GDBItem in newGDBItemsContainer)
{
//Do Something with the GDB.
}
Get a specific "GDBProjectItem"
GDBProjectItem GDBProjItem = Project.Current.GetItems<GDBProjectItem>().FirstOrDefault(item => item.Name.Equals("myGDB"));
Get all "ServerConnectionProjectItems"
IEnumerable<ServerConnectionProjectItem> newServerConnections = null;
newServerConnections = project.GetItems<ServerConnectionProjectItem>();
foreach (var serverItem in newServerConnections)
{
//Do Something with the server connection.
}
Get a specific "ServerConnectionProjectItem"
ServerConnectionProjectItem serverProjItem = Project.Current.GetItems<ServerConnectionProjectItem>().FirstOrDefault(item => item.Name.Equals("myServer"));
Get all folder connections in a project
//Gets all the folder connections in the current project
var projectFolders = Project.Current.GetItems<FolderConnectionProjectItem>();
foreach (var FolderItem in projectFolders)
{
//Do Something with the Folder connection.
}
Get a specific folder connection
//Gets a specific folder connection in the current project
FolderConnectionProjectItem myProjectFolder = Project.Current.GetItems<FolderConnectionProjectItem>().FirstOrDefault(folderPI => folderPI.Name.Equals("myDataFolder"));
Gets a specific "LayoutProjectItem"
LayoutProjectItem layoutProjItem = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals("myLayout"));
Get all layouts in a project
//Gets all the layouts in the current project
var projectLayouts = Project.Current.GetItems<LayoutProjectItem>();
foreach (var layoutItem in projectLayouts)
{
//Do Something with the layout
}
Get a specific "GeoprocessingProjectItem"
GeoprocessingProjectItem GPProjItem = Project.Current.GetItems<GeoprocessingProjectItem>().FirstOrDefault(item => item.Name.Equals("myToolbox"));
Get all GeoprocessingProjectItems in a project
//Gets all the GeoprocessingProjectItem in the current project
var GPItems = Project.Current.GetItems<GeoprocessingProjectItem>();
foreach (var tbx in GPItems)
{
//Do Something with the toolbox
}
Search project for a specific item
List<Item> _mxd = new List<Item>();
//Gets all the folder connections in the current project
var allFoldersItem = Project.Current.GetItems<FolderConnectionProjectItem>();
if (allFoldersItem != null)
{
//iterate through all the FolderConnectionProjectItems found
foreach (var folderItem in allFoldersItem)
{
//Search for mxd files in that folder connection and add it to the List<T>
//Note:ArcGIS Pro automatically creates and dynamically updates a searchable index as you build and work with projects.
//Items are indexed when they are added to a project.
//The first time a folder or database is indexed, indexing may take a while if it contains a large number of items.
//While the index is being created, searches will not return any results.
_mxd.AddRange(folderItem.GetItems());
}
}
Refresh the child item for a folder connection Item
var contentItem = Project.Current.GetItems<FolderConnectionProjectItem>().First();
//var contentItem = ...
//Check if the MCT is required for Refresh()
if (contentItem.IsMainThreadRequired)
{
//QueuedTask.Run must be used if item.IsMainThreadRequired
//returns true
QueuedTask.Run(() => contentItem.Refresh());
}
else
{
//if item.IsMainThreadRequired returns false, any
//thread can be used to invoke Refresh(), though
//BackgroundTask is preferred.
contentItem.Refresh();
//Or, via BackgroundTask
ArcGIS.Core.Threading.Tasks.BackgroundTask.Run(() =>
contentItem.Refresh(), ArcGIS.Core.Threading.Tasks.BackgroundProgressor.None);
}
Select an item in the Catalog pane
//Get the catalog pane
ArcGIS.Desktop.Core.IProjectWindow projectWindow = Project.GetCatalogPane();
//or get the active catalog view...
//ArcGIS.Desktop.Core.IProjectWindow projectWindow = Project.GetActiveCatalogWindow();
//eg Find a toolbox in the project
string gpName = "Interacting with Maps.tbx";
var toolbox = Project.Current.GetItems<GeoprocessingProjectItem>().FirstOrDefault(tbx => tbx.Name == gpName);
//Select it under Toolboxes
projectWindow.SelectItemAsync(toolbox, true, true, null);//null selects it in the first container - optionally await
//Note: Project.Current.GetProjectItemContainer("GP") would get toolbox container...
//assume toolbox is also under Folders container. Select it under Folders instead of Toolboxes
var foldersContainer = Project.Current.ProjectItemContainers.First(c => c.Path == "FolderConnection");
//We must specify the container because Folders comes second (after Toolboxes)
projectWindow.SelectItemAsync(toolbox, true, true, foldersContainer);//optionally await
//Find a map and select it
var mapItem = Project.Current.GetItems<MapProjectItem>().FirstOrDefault(m => m.Name == "Map");
//Map only occurs under "Maps" so the container need not be specified
projectWindow.SelectItemAsync(mapItem, true, false, null);
Delete_Layout
//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));
}
}
Reference layout project items and their associated layout
//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"));
Delete a report
//Note: Call within QueuedTask.Run()
//Reference a reportitem in a project by name
ReportProjectItem reportItem = Project.Current.GetItems<ReportProjectItem>().FirstOrDefault(item => item.Name.Equals(reportName));
//Check for report item
if (reportItem == null)
return Task.FromResult<bool>(false);
//Delete the report from the project
return Task.FromResult<bool>(Project.Current.RemoveItem(reportItem));
Target Platforms: Windows 11, Windows 10
ArcGIS Pro version: 3 or higher.