Hello, I would like to programmatically select a feature editing template from the list of favorites. For example, when the user clicks a button, the list of favorite templates appears and the first item under a certain folder gets selected. Is there a recommended way of doing this?
Hi,
Have you tried GetTemplates method from MappingExtensions?
More info here.
There is ArcGIS Pro SDK community sample for choosing template from list:
https://github.com/Esri/arcgis-pro-sdk-community-samples/tree/master/Editing/TransferAttributes
OK, this might be an option, but actually I was planning to go with the existing UI: Selecting a template from the list of favorites so that it appears selected, expands, and activates its default tool.
It seems I can get hold of the TemplateFoldersVM in esri_editing_CreateFeaturesDockPane and its children via reflection, but I'd prefer a supported solution.
Hello,
Currently there is no method in the API to access the set of favorite templates. Access to templates is currently only from a map member (layer or standalone table) using the GetTemplates method. I will add an issue to our backlog to address this in a future release.
Narelle
Thank you Narelle, I really appreciate it and I am looking forward to working with this future release.
For those interested, my current approach is this:
static bool SelectFirstTemplateFromFolder(string folderName)
{
var pane = FrameworkApplication.DockPaneManager.Find(DAML.Dockpane.esri_editing_CreateFeaturesDockPane);
pane.Activate();
var paneType = pane.GetType();
var pi = paneType.GetProperty("SubPanelIndex");
pi?.SetValue(pane, 0);
pi?.SetValue(pane, 1); // Switch to Favorites
pi = paneType.GetProperty("TemplateFoldersVM");
var templateFoldersVM = pi?.GetValue(pane);
pi = templateFoldersVM?.GetType().GetProperty("RootFolderChildren");
if (pi?.GetValue(templateFoldersVM) is IEnumerable col)
{
foreach (var item in col)
{
var itemType = item.GetType();
pi = itemType.GetProperty("Name");
var name = pi.GetValue(item);
if (Equals(name, folderName))
{
pi = itemType.GetProperty("Children");
if (pi?.GetValue(item) is IEnumerable children)
{
var enumerator = children.GetEnumerator();
if (enumerator.MoveNext())
{
var child = enumerator.Current;
var childType = child.GetType();
pi = childType.GetProperty("IsSelected");
pi.SetValue(child, false);
pi.SetValue(child, true);
return true;
}
}
break;
}
}
}
return false;
}