Programmatically select template from favorites

413
4
01-30-2023 03:32 AM
FridjofSchmidt
Occasional Contributor

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?

0 Kudos
4 Replies
GKmieliauskas
Esri Regular Contributor

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 

0 Kudos
FridjofSchmidt
Occasional Contributor

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.

0 Kudos
NarelleChedzey
Esri Contributor

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

FridjofSchmidt
Occasional Contributor

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;
}

 

0 Kudos