ProConcepts Content and Items

Uma Harano edited this page Jun 26, 2018 · 3 revisions

This ProConcepts will go cover content in Pro, its usage, and relevant API functionality.

Language:      C# and Visual Basic
Subject:       Content
Contributor:   ArcGIS Pro SDK Team <arcgisprosdk@esri.com>
Organization:  Esri, http://www.esri.com
Date:          6/7/2018  
ArcGIS Pro:    2.2  
Visual Studio: 2015, 2017

In this topic

Overview

In Pro, content is represented as Items (Item topic 9110). There are two categories of Items:

  • Content that is stored in, or referenced by, the Project document. This content, is referred to as project content (or project "items")* and includes maps, layouts, styles, toolboxes, folders, etc.
  • Content that is browsed by Pro and is external to the project. Content can be browsed from folders, portal and online, geodatabases, and toolboxes and includes text files, xml files, folders, database connection files, layer files, task files, mxds, sxds, etc. This content, is referred to as external content (or external "items").

A complete list of the supported data types and items for Pro can be found here

*Content can also be included within Favorites at 2.0.

Project Content

Project content, or project "items", lives within the project. At some point in time, project content was either added or imported into the project from an external source or was created (and saved) in a Pro session. Once in a project, content can packaged and shared (see Project Package)

In the API, project "items" all include the suffix ProjectItem in their class name and derive from ArcGIS.Desktop.Core.Item (by way of a couple of internal classes not relevant to the public API). Project item classes implement the interface IProjectItem (topic 15851) which is the required parameter type for adding and removing content to and from Pro ( Project.Current.AddItem(IProjectItem item), topic 15947, and Project.Current.RemoveItem(IProjectItem item), topic 15951). Adding content to the project is discussed in detail in ItemFactory and AddItem.

The public API currently provides the following project items:

Class Namespace Assembly
FolderConnectionProjectItem ArcGIS.Desktop.Catalog ArcGIS.Desktop.Catalog.dll
GDBProjectItem ArcGIS.Desktop.Catalog ArcGIS.Desktop.Catalog.dll
GeoprocessingProjectItem ArcGIS.Desktop.GeoProcessing ArcGIS.Desktop.GeoProcessing.dll
HistoryProjectItem ArcGIS.Desktop.GeoProcessing ArcGIS.Desktop.GeoProcessing.dll
LayoutProjectItem ArcGIS.Desktop.Layouts ArcGIS.Desktop.Layouts.dll
LocatorsConnectionProjectItem ArcGIS.Desktop.Catalog ArcGIS.Desktop.Catalog.dll
MapProjectItem ArcGIS.Desktop.Mapping ArcGIS.Desktop.Mapping.dll
ReviewerBatchJobProjectItem ArcGIS.Desktop.DataReviewer ArcGIS.Desktop.DataReviewer.dll
ReviewerResultsProjectItem ArcGIS.Desktop.DataReviewer ArcGIS.Desktop.DataReviewer.dll
StyleProjectItem ArcGIS.Desktop.Mapping ArcGIS.Desktop.Mapping.dll
ServerConnectionProjectItem ArcGIS.Desktop.Catalog ArcGIS.Desktop.Catalog.dll
TaskProjectItem ArcGIS.Desktop.TaskAssistant ArcGIS.Desktop.TaskAssistant.dll

Portal Content

Portal content is any content that is retrieved from a portal or online. In the Pro UI, portal content shows up in the catalog pane on the "Portal" tab (and in a Catalog view with "Portal" selected in the breadcrumb\text box). Portal content, in the Pro API, is organized into 3 types*:

  • Items
  • Folders
  • Groups

Portal content derives from ArcGIS.Desktop.Core.Portal.OnlineItem topic 18241, which, in turn, derives from ArcGIS.Desktop.Core.Item topic 9109, the base class for all content in Pro. Note: the ArcGIS.Desktop.Core.Portal namespace is in both the ArcGIS.Desktop.Core.dll and the ArcGIS.Desktop.Catalog.dll assemblies.

*Use portal.GetSignOnUsername to get portal user information and portal.GetPortalInfoAsync to get the logged on user (or anonymous) view of a portal topic 19170.

Portal Items

Of the 3 types in the API, "Items" are the primary content item and represent over 100 different content types that are currently supported by portal such as web maps, feature services, packages, styles, microsoft office document files, images, mxds, add-ins, and so on (see supported data types and items and PortalItemType enumeration for the complete list of "item" content types). Items are represented by the ArcGIS.Desktop.Core.Portal.PortalItem class topic 18175. Because PortalItem "is a" Item, it can be passed as the parameter to any of the class factories that consume items (eg MapFactory or LayerFactory) assuming that the provided item represents content of the correct type. Portal items can be retrieved either by a portal.GetUserContentAsync call or via a search using portal.SearchForContentAsync.

  var portal = ArcGISPortalManager.Current.GetActivePortal();
  var owner = portal.GetSignOnUsername();
  //get the user content
  var userContent = await portal.GetUserContentAsync(owner);
  //folders...
  foreach (var pf in userContent.PortalFolders) {
    ...

  //items
  foreach (var pi in userContent.PortalItems) {
    ...

Execute a query to retrieve all web maps visible to the user, within his or her organization:

 //assume signed on user is a member of an organization...
 //get the organization id
 var portalInfo = await portal.GetPortalInfoAsync();
 var orgid = orgid = portalInfo.OrganizationId;

 var query = PortalQueryParameters.CreateForItemsOfType(PortalItemType.WebMap);
 query.Limit = 100;
 query.OrganizationId = orgid;
 //query the organization for web maps...
 PortalQueryResultSet<PortalItem> results = await portal.SearchForContentAsync(query);
 
 //create a map (in Pro) from the first item
 var result = results.First();
 QueuedTask.Run(() => {
    if (MapFactory.Instance.CanCreateMapFrom(result))
        MapFactory.Instance.CreateMapFromItem(result);
    ...

Portal items that represent file types such as packages, documents, style files, images, etc. can be downloaded to disk via the portalItem.GetItemDataAsync method. This retrieves the original item that (was uploaded) from portal and streams it to the file name you provide, on disk, as the parameter to GetItemDataAsync. Portal items that have no downloadable content will write out an empty file.

 //assume we query for some content
 var results = await portal.SearchForContentAsync(query);

 var portalItem = results.Results.First();//first item
 var folder = @"E:\Temp\Download\";
 var path = System.IO.Path.Combine(folder, portalItem.Name);

 //download the item
 await portalItem.GetItemDataAsync(path);

Portal Folders

Users can organize their portal or online content into folders. Folders are represented by the ArcGIS.Desktop.Core.Portal.PortalFolder class topic 18157 and can be retrieved via a portal.GetUserContentAsync method call (which can return all of a user's content including their folders and items). The corollary for portal.GetUserContentAsync in the Pro UI is the content retrieved for the "My Content" tab in either of the catalog pane or a catalog view.

 //Retrieve all the portal folders for the active user
 var portal = ArcGISPortalManager.Current.GetActivePortal();
 var owner = portal.GetSignOnUsername();
 //get the user content
 var userContent = await portal.GetUserContentAsync(owner);
 //folders...
 foreach (var pf in userContent.PortalFolders) {
    ...

Portal Groups

Users can also participate in groups. Groups are represented by the ArcGIS.Desktop.Core.Portal.PortalGroup class topic 18157 and those groups visible to a particular portal user can be retrieved via a portal.GetGroupsFromUserAsync method call. This corresponds to the content retrieved via the "Groups" tab in the catalog pane or view.

 //Retrieve all the groups visible to the current signed on user
 var owner = portal.GetSignOnUsername();
 var groups = await portal.GetGroupsFromUserAsync(owner);
 foreach (var group in groups) {
   ...

External Content

Any content that can be browsed (and can be indexed by Pro for browsing) is considered "external content". External content items derive from ArcGIS.Desktop.Core.Item same as project content items. External content items represent the many different file types or folder types (images, text files, file geodatabase folder, style files, zip archives, etc.) that can exist online or on a physical disk drive whether it can be added to Pro or not. For example, when enumerating the contents of a folder, items are returned for all the content, not just the Pro specific content.

Note: The majority of the external content types derive from Item via "Desktop.Internal" classes (as do project items)*. This is an implementation detail not relevant to the public API. Simply treat them as "Items" in your code because that is what they are. The underlying "Desktop.Internal" classes provide Catalog the functionality it needs to show special icons, customize context menus, provide browsing support (for containers) and that sort of thing.

*Some items are instantiated as "ProjectItem" classes directly by ItemFactory.Instance.Create. These are covered in the next section.

ItemFactory and AddItem

Creating and adding content to a project is a three step process:

  1. Create a content item using ItemFactory.Instance.Create using the path or url to the content (whether on disk or online).

  2. Test the returned content for IProjectItem* to see if it can be added to the project.

  3. If it implements IProjectItem, add the content to the project via Project.Current.AddItem. AddItem returns true if the item was successfully added.

Internally, the process of "adding" ensures the item is stored within the correct container (Maps for Maps, Layouts for Layouts, Toolboxes for Toolboxes, etc.) and is added to the internal project repository. Note: Project.Current.AddItem must be called within a QueuedTask lambda.

This example creates a layer file item and tests it to see if it can be added to the Project. (The test will fail and show the message box - layer files can only be added to maps (with LayerFactory) - not projects)

  //test to see if a layer file can be added
  string path = @"E:\Pro\USA\Us_States.lyrx";
  Item item = ItemFactory.Instance.Create(path, ItemFactory.ItemType.PathItem);
  if (item is IProjectItem)
      QueuedTask.Run(() => Project.Current.AddItem((IProjectItem)item));
   else
      //A layer file can NOT be added to a project. It can only be added to a map
      MessageBox.Show($"{item.Path} cannot be added to a project", "Content");

*If you already know that an item is an IProjectItem (e.g. experience, familiarity, snippet, etc.) skip #2 and simply cast the returned item from ItemFactory Create directly. In this example, we know a folder connection is a IProjectItem:

 //Add a folder connection
 string path = @"E:\Pro";
 //Cast item to IProjectItem directly
 var folderItem = ItemFactory.Instance.Create(path) as IProjectItem;
 //Add it
 QueuedTask.Run(() => Project.Current.AddItem(folderItem));

Calls to ItemFactory.Instance.Create create the project item directly in the following cases:

  • FolderConnectionProjectItem (e.g. folders)
  • GDBProjectItem (e.g. .gdb, .sde files)
  • GeoprocessingProjectItem (e.g. .tbx, .gpkx, .pyt files)
  • LocatorsConnectionProjectItem (e.g. .loc files)
  • ServerConnectionProjectItem (e.g. .ags, .wcs, .wms, .wfs, .wmts files)
  • TaskProjectItem (e.g. task files)

However, these content items still have to be added to the project with AddItem. For example:

//These are equivalent workflows
string folderPath = "@C:\\myDataFolder";

//Get an IProjectItem for the folder
var folderItem = ItemFactory.Instance.Create(path) as IProjectItem;

//Or, get a FolderConnectionProjectItem for the folder
var folderItem = ItemFactory.Instance.Create(path) as FolderConnectionProjectItem;

-- MUST call Project.Current.AddItem if you want to add it! --

ItemFactory and Import

Certain file types are silently imported when they are added to a project such as map packages or 10x formatted files (mxds, sxds, styles, etc.) that require conversion. External content types that support importing via the API implement ArcGIS.Desktop.Core.IProjectMultiItem (refer to topic 15858) and can be passed to Project.Current.ImportItem to "add" the content to the project as well using the standard Project.Current.AddItem call. Generally, all 10x file formats that can be imported to Pro support IProjectMultiItem as well as map packages and server connection files.

Using either of Project.Current.ImportItem or Project.Current.AddItem with a IProjectMultiItem adds the content to the project*. However, in those cases where more than one item may be created in the project, ImportItem returns the enumeration directly whereas AddItem does not. The canonical case being an mxd that contains both a map and a layout will create two items in the project when it is added.

*Internally, AddItem calls ImportItem for any IProjectMultiItems to perform the "add".

For example, either of these workflows can be used to import an mxd into Pro:

  string mxd = @"E:\Pro\USA\OceanBasemap.mxd";
  //Either...
  var addItem = ItemFactory.Instance.Create(mxd, ItemFactory.ItemType.PathItem) as IProjectItem;
  await QueuedTask.Run(() => Project.Current.AddItem(addItem));
  
  //Or...
  var importItem = ItemFactory.Instance.Create(mxd, ItemFactory.ItemType.PathItem) as IProjectMultiItem;
  var items = await QueuedTask.Run(() => Project.Current.ImportItem(importItem));

  //And, of course, MapFactory.Instance.CreateMapFromItem.... not shown

To check whether an item can use Project.Current.ImportItem, test for the presence of the IProjectMultiItem interface:

  var item  = ItemFactory.Instance.Create(itemPath, ItemFactory.ItemType.PathItem);
  //Can it be imported?
  if (item is IProjectMultiItem) {
     //yes it can
  }
  //Can it be added?
  else if (item is IProjectItem) {
     //yes it can
  }

Items and Factories

The following factories provide "create" methods that consume Items:

  • ArcGIS.Desktop.Mapping.MapFactory
  • ArcGIS.Desktop.Mapping.LayerFactory
  • ArcGIS.Desktop.Mapping.StandaloneTableFactory

This is useful if you are adding layer files or feature classes (as standalone tables) to a map or maps to a project and have already retrieved an item to the external content at some earlier point in your workflow (e.g. you retrieved a layer file item from a browse of a folder connection). For example:

  //Use the MapFactory to create a map from an external item (e.g. a mapx file or and mxd)

  Item mapItem = ...   //retrieved earlier from ItemFactory or from browsing a folder...

  return QueuedTask.Run(() => {
        // verify that a map can be created from the item
        if (MapFactory.Instance.CanCreateMapFrom(mapItem)) {
          // creates a new map and adds it to the project.  Also opens the mapview
          MapFactory.Instance.CreateMapFromItem(mapItem);
        }
      });

Of course, you can also use overloads on LayerFactory and StandaloneTableFactory that take the physical path ("Uri") to the content without creating an item first

Getting Item Content

GetItems

Content can either be accessed via a GetItems<T> call on the parent item (for example a folder or geodatabase) or on the project instance (or via portal as portal items, ref. portal content). If an item has children that can be enumerated with GetItems then its IsContainer property will be true. Calling GetItems on the project instance enumerates all of the project items - that is, all of the content that has been added to the project at that point in time - whereas calling GetItems on a folder or geodatabase item, for example, enumerates all of the external items that they each contain (regardless of whether the folder or geodatabase have been added to the project or not). GetItems on a "container" (like a folder or geodatabase) always searches one level deep. To perform a multi-level search (e.g. to drill down through a folder hierarchy), the returned Items should be tested for "IsContainer" equals true and their content likewise enumerated with GetItems (recursively) and so on.

As GetItems<T> is a generic function, it can be constrained to return only items of a particular type using its template parameter "T". This is especially useful when searching the content of the project for just items of a particular type. For example:

  //get just the maps - use MapProjectItem
  var maps = Project.Current.Getitems<MapProjectItem>();

  //Get a specific map
  var map = Project.Current.GetItems<MapProjectItem>().FirstOrDefault(
                                               m => m.Name == "Map 1");

  //get just the database connections - use GDBProjectItem
  var gdbs = Project.Current.Getitems<GDBProjectItem>();

  //get just the layouts - use LayoutProjectItem
  var layouts = Project.Current.Getitems<LayoutProjectItem>();

  //etc.

  //Just get them all - no constraints
  var allItems = Project.Current.GetItems<Item>();

As GetItems<T> returns an IEnumerable, the result can be extended with Linq expressions to further refine and filter the retrieved content. For example, this is a search on the first folder connection of a given name in the project for any mxd files it contains:

    //Declarations in a view model, for example
    private static readonly object _lock = new object();
    private ObservableCollection<Item> _mxdResults = = new ObservableCollection<Item>();

    ...
    //Call to BindingOperations to sync access to the ObservableCollection, eg in the ctor
    BindingOperations.EnableCollectionSynchronization(_mxdResults , _lock);
    ...

    ///<summary>Property for binding of search results</summary>
    public ObservableCollection<Item> MxdResults => _mxdResults ;

    /// <summary>Performs the search for mxds on the given folder</summary>
    private async Task SearchFirstFolderForMxdsAsync(string Folder) {
       // find the folder project item - Use Ling FirstOrDefault extension on the returned IEnumerable
       var folder = Project.Current.GetItems<FolderConnectionProjectItem>().FirstOrDefault(f => f.Path == Folder);
       await QueuedTask.Run(() => {
          lock(_lock) {
             _mxdResults.Clear();
             //Call GetItems to get the folder content (one level deep)
             foreach (var item in folder.GetItems()) {
                 if (item.Name.EndsWith("mxd"))
                    _mxdResults.Add(item);
             }
        }
     }

Content returned from GetItems are snapshot collections. They are not refreshed if the child content of given parent project item changes (e.g. a new file or feature class is added). Content must be re-queried.

Project also provides a public Task<IEnumerable<Item>> SearchAsync(string query) function that supports a keyword search of project item content based on the information that a given project item may contain in its metadata (e.g. in its keywords, tags, summary, etc.). Refer to topic 9205 in the API Reference.

FindItems

FindItems is useful when you already have a path or catalog path to an item on disk or in a geodatabase. FindItems first searches for the content in the Pro index (which includes content that has been added to the project). If the item is found in the index, the item is returned. If the item is not found in the index, FindItems checks the path to assure the content is valid, and, if so, creates a new item. Additionally, if the path is either to a folder or a file geodatabase, then the item is added to the project and will be indexed. If the path is bad, null is returned.

 //retrieve a pdf
 var pdfPath = @"E:\Temp\Layout1.pdf";
 var pdf = Project.Current.FindItem(pdfPath);

 //retrieve a folder (the folder will be added to the project)
 var folderPath = @"E:\Data\SampleData";
 var folder = Project.Current.FindItem(folderPath);

 //retrieve a feature class and select it in the Catalog pane (assuming the catalog pane has focus)
 var fcPath = @"E:\Pro\CommunitySampleData\Interacting with Maps.gdb\Crimes";
 var fc = Project.Current.FindItem(fcPath);

If the item(s) is a project content item, it can be further cast to the relevant "ProjectItem" class (i.e. "project items" like map, style, layout, scene, toolbox, etc.)

Item Metadata

The Item class includes these two properties which provide access to the item’s metadata as an XML document in the ArcGIS metadata format.

An item’s metadata lets you document the item’s content. For example, you can describe where the item’s data came from, how recent it is, what processes have been run on it, what information is available in the fields of its attribute table, and how the item should be used including any legal disclaimers regarding that use. Learn more about viewing and editing metadata in ArcGIS Pro: view and edit metadata.

The item’s metadata is returned as a string representing the ArcGIS metadata XML document. Use that string to create an XML document that can be manipulated using the XML parser of your choice. For example, you can transform the provided XML to an HTML page that can be displayed outside of ArcGIS Pro. Or, you can use the XML parser’s methods to programmatically update the metadata content and save the changes back to the original item using the SetXml method. The metadata saved back to the item must be in the ArcGIS metadata format.

The ArcGIS metadata format is documented in the ArcGIS Metadata Toolkit, which can be downloaded from the Esri Support site. The toolkit contains an XML DTD that defines the structure of an ArcGIS metadata XML document. It also contains an Excel spreadsheet that documents the elements, and indicates if they are populated automatically by ArcGIS, which metadata styles they participate in, where they appear in the metadata editor, and so on. Sample XML documents are also provided to help correlate the ArcGIS metadata format with standard XML formats such as the FGDC CSDGM and ISO 19115/19139 standards.

Catalog Context

The context (usually "what is selected") of either the Catalog Pane or a Catalog View can be accessed via their ArcGIS.Desktop.Core.IProjectWindow interface (see topic 14659).

To retrieve the catalog pane or any catalog view use:

  • Project.GetActiveCatalogWindow() if you want the active catalog view. If no catalog view is active, this returns null.
  • Project.GetCatalogPane() if you want the catalog pane (whether it is active or not). Specify createIfNecessary=false if you do not the catalog pane created if it has not been created previously.
  • FrameworkApplication.ActiveWindow and test it for IProjectWindow. If the ActiveWindow is an IProjectWindow it can be either of the catalog pane or a catalog view otherwise the IProjectWindow will be null.
  • FrameworkApplication.Panes enumeration for a specific catalog view (active or not).
 //Get the active catalog window - either the pane ~or~ a catalog view
 var window = FrameworkApplication.ActiveWindow as ArcGIS.Desktop.Core.IProjectWindow
 if(window != null) {
  ...

 //Get the Catalog pane (whether it is the active window or not)
 var catalog = Project.GetCatalogPane();//will create the pane if needed
 ...

 //enumerate the panes collection
 foreach (var pane in FrameworkApplication.Panes) {
 ...

Getting Selected Items

Accessing an item selection requires the IProjectWindow (catalog pane or view) whose selection you want access and enumerating its IEnumerable<Item> SelectedItems { get; } property. Each catalog window maintains its own independent selection (view or the pane). Subscribe to the ProjectWindowSelectedItemsChangedEvent event to be notified of selection changes.

//Get the active catalog window - either the pane ~or~ a catalog view
var window = FrameworkApplication.ActiveWindow as ArcGIS.Desktop.Core.IProjectWindow
var item = window?.SelectedItems.First();
//do something with the selection...

//Get the Catalog pane (whether it is the active window or not)
var catalog = Project.GetCatalogPane();//will create the pane if needed
//get whatever is selected on it
var items = catalog.SelectedItems;

Selecting Items

Selection is performed on project items on the project tab of the catalog pane or catalog views. To perform a selection of items on a catalog window, use its IProjectWindow.SelectItemAsync method (topic19182.html). In no particular order:

  • Retrieve the item to be selected
  • Get the IProjectWindow (catalog pane or view) you want to select the item on
  • [Optional] Get the container you want the item selected in (some items can live in more than one container)

Retrieve the item using any of the methods available for searching or browsing for items such as GetItems. The IProjectWindow should be acquired as described in the Catalog Context above. The last parameter to SelectItemAsync is the container within which you want the specified item to be selected. Catalog content can, in some cases, be browsed either via its "primary" container or, because it may represented as a physical file or folder, via the Folders container (assuming that its parent folder has been added to the project). The same is true of geodatabase content, such as a feature class, which can be browsed via its parent geodatabase item within the "Databases" container or, possibly, the "Folders" container.

When the SelectItemAsync container parameter is set to null, the first occurrence of the item found in any container is the one that is selected. If Multiple containers can hold a particular item, they will be searched in the same order as their visual order/arrangement within the catalog window (pane or view) you are selecting it in. For example, selecting a map or toolbox:

  //"projectWindow" can be either the catalog pane or a catalog view...
  //Maps only occur in the "Maps" container so no container need be specified
  string mapName = "Map";
  var map = Project.Current.GetItems<MapProjectItem>().FirstOrDefault(m => m.Name == mapName);
  projectWindow.SelectItemAsync(map, true, null);//optionally "await"

  //Select the toolbox in the Toolboxes container. Because it is searched
  //before "Folders", and null is specified, the toolbox within the Toolboxes container 
  //will be selected.
  string gpName = "Interacting with Maps.tbx";
  var toolbox = Project.Current.GetItems<GeoprocessingProjectItem>().FirstOrDefault(tbx => tbx.Name == gpName);
  projectWindow.SelectItemAsync(toolbox, true, null);//optionally "await"

Specifying a Container

For those cases where the container within which you want a particular item selected cannot be inferred, the container must be specified. To access the container for use in selecting items, use Project.Current.ProjectItemContainers to enumerate through the available containers.

Containers have a localizable display name (their "Name" attribute) which is shown in the catalog windows as well as a non-localizable "type" or "Path" attribute. The "Path" attribute is the preferred attribute to use when identifying a specific container. It correlates with the value for the "key" parameter for Project.Current.GetProjectItemContainer(string key) as well. The complete set of containers in catalog is listed below along with their display name and path.

Note: Project.Current.ProjectItemContainers, like many collections in Pro, is a snapshot selection. What that means is, depending on the actual content of a given project at any given point in time, the list of instantiated project containers can vary. In other words, depending on your project content, some containers can be null. (Databases, Folders, Layouts, Locators, Maps, Styles, and Toolboxes are always present). There are also non-visible internal project containers within the collection of containers which can be ignored.

Public Containers

Display Name (English) Path or "Key" (Non-localizable) Item content
Databases GDB Database content
Folders FolderConnection Files and Folders
Layouts Layout Layouts
Locators LocatorsConnection Locators
Maps Map Maps
Raster Function Templates RasterFunctionTemplates Raster function templates
Reviewer Batch Jobs DataReviewerBatchJobs Reviewer batch jobs
Reviewer Results DataReviewerResources Reviewer results
Servers ServerConnection Server connections
Styles Style Styles
Tasks Task Tasks
Toolboxes GP Toolboxes
Workflows WorkflowConnection Workflows

Internal Containers (non-visible)

DisplayUnitEnvironment DisplayUnitEnvironment Internal use
FindProviderSettings FindProviderSettings Internal use
Geoprocessing History GPHistory Internal use
Ortho Mapping OrthoMappingWorkspace Internal use
Reports Report Internal use
Raster Function History RFxHistory Internal use

Use the path attribute to select a given container from the collection or the key value with GetProjectItemContainer - depending on your project content some containers can be null:

 //Selecting the maps container
 var maps = Project.Current.ProjectItemContainers.First(c => c.Path == "Maps");
 //or with key
 maps = Project.Current.GetProjectItemContainer("Map");

 //Selecting the Folders container
 var folders = Project.Current.ProjectItemContainers.First(c => c.Path == "FolderConnection");
 folders = Project.Current.GetProjectItemContainer("FolderConnection");

//Selecting the Databases container
 var databases = Project.Current.ProjectItemContainers.First(c => c.Path == "GDB");
 databases = Project.Current.GetProjectItemContainer("GDB");

Assuming the desired item has been retrieved along with the relevant catalog window and container, perform the selection: Select the given item in the container using its SelectItemAsync method.

  //retrieve a feature class and select it in the Catalog pane (assuming the catalog pane has focus)
  var fcPath = @"E:\Pro\CommunitySampleData\Interacting with Maps.gdb\Crimes";
  var fc = Project.Current.FindItem(fcPath);

  //Get the Folders container
  var folderContainer = Project.Current.GetProjectItemContainer("FolderConnection");

  //Select the fc
  var projectWindow = Project.GetCatalogPane();
  await projectWindow.SelectItemAsync(fc, true, folderContainer);

 //Get a toolbox and select it in the Folder container, assuming its parent
 //folder has been added to the list of Folders
 string gpName = "Interacting with Maps.tbx";
 var toolbox = Project.Current.GetItems<GeoprocessingProjectItem>().FirstOrDefault(tbx => tbx.Name == gpName);
 var folderContainer = Project.Current.ProjectItemContainers.First(c => c.Path == "FolderConnection");
 
 var projectWindow = Project.GetCatalogPane();
 await projectWindow.SelectItemAsync(toolbox, true, folderContainer);
 

ProjectWindowSelectedItemsChangedEvent

Subscribe to ArcGIS.Desktop.Core.Events.ProjectWindowSelectedItemsChangedEvent to be notified of selection changes on any catalog window (pane or views). The ProjectWindowSelectedItemsChangedEventArgs identifies the IProjectWindow and its DAML Id, that triggered the selection changed event. The IProjectWindow con the event args an be accessed to retrieve what is selected.

//register for selection changed (eg in a dockpane)
internal class LayoutEventSpyViewModel : DockPane {

    protected override Task InitializeAsync() {
ArcGIS.Desktop.Core.Events.ProjectWindowSelectedItemsChangedEvent.Subscribe((args) => {
        var names = string.Join(",", args.IProjectWindow.SelectedItems.Select(i => i.Name).ToList());
        //etc
      });
    ...

Home

Developing with ArcGIS Pro


Framework

    Add-ins

    Configurations

    Customization

    Styling


Content


CoreHost


DataReviewer


Editing


Geodatabase


Geometry

    Relational Operations


Geoprocessing


Layouts


Map Authoring


Map Exploration

    Map Tools


Raster


Sharing


Tasks


Utility Network


Workflow Manager


Reference

    2.0 Migration

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.