Setting construction tool options on template via CIM

541
1
08-31-2022 12:31 PM
DanielRouleau
Occasional Contributor

I'm trying to adapt the EditingTemplates CreateTemplateWithCIM sample to write a template in which I have specified a default construction tool, and want to set some tool options on this custom construction tool. What I am seeing is that, despite trying a number of different ways to do so, the tool options are never persisted into the template using CIM. The tool options collection is always null when the construction tool is constructed. Setting the tool options using the Manage Template dialog works fine and everything works there. I tried this originally with Pro 2.9 and then adapted the sample to Pro 3.0 and still am not having luck.

 

Any tips on getting these tool options to save with the newly created template using CIM? Here is the relevant chunk of code that I've tried adapting.

//get the CIM layer definition
var layerDef = layer.GetDefinition() as CIMFeatureLayer;

//set new template values
var myTemplateDef = new CIMRowTemplate();
myTemplateDef.Name = "Daniel Template With Construction";
myTemplateDef.Description = "some description";

// set the default construction tool to our custom tool
myTemplateDef.SetDefaultToolID("EditingTemplates_Tools_ConstructFacilitiesTool");
myTemplateDef.AllowToolID("EditingTemplates_Tools_ConstructFacilitiesTool");

// Add default tool options for this construction tool
var toolOptions = new Dictionary<string, object>();
toolOptions.Add("CustomSubtype", "MySubtypeCode");

myTemplateDef.ToolOptions = new[]
{
new CIMEditingTemplateToolOptions()
					  {
                          //ToolProgID = "EditingTemplate_Tools_ConstructFacilitiesTool", I tried this to no avail
                          ToolProgID = "cdf8db34-6880-4e16-8253-145d739de379", // id from daml
						  Options = toolOptions,
					  }
				};

var layerTemplates = layerDef.FeatureTemplates?.ToList();
if (layerTemplates == null)
	layerTemplates = new List<CIMEditingTemplate>();

//add the new template to the layer template list
layerTemplates.Add(myTemplateDef);

//update the layerdefinition with the templates
layerDef.FeatureTemplates = layerTemplates.ToArray();

// check the AutoGenerateFeatureTemplates flag, 
//     set to false so our changes will stick
if (layerDef.AutoGenerateFeatureTemplates)
	layerDef.AutoGenerateFeatureTemplates = false;

//and commit
layer.SetDefinition(layerDef);

 

0 Kudos
1 Reply
Wolf
by Esri Regular Contributor
Esri Regular Contributor

There is a tool called the CIMViewer that you can download from here:  Esri/arcgis-pro-sdk-cim-viewer (github.com) It's an add-in and a version for ArcGIS Pro 3.0 is available.  I would recommend downloading and installing the CIM Viewer and set the tool options using the Manage Template dialog and then use CIM Viewer to view (and save) the CIM definition of your feature layer (modified using ArcGIS Pro).  Then compare the CIM with the CIM generated by your add-in.  There's probably some type of property that is not set by your program. 

0 Kudos