modifying some values in an active template

857
2
Jump to solution
01-05-2019 04:05 PM
SergueiSokolov
New Contributor III

I’ll need to Create a feature using the current template while modifying some values in an active template (i.e. setting a common note or specific Asset ID value "before" creating a feature with the template, other default values in the template are Ok). I want to avoid two-steps process - create a feature with the template and then modify it in second Edit operation.

var myTemplate = ArcGIS.Desktop.Editing.Templates.EditingTemplate.Current;

var myGeometry = _geometry;

var op = new ArcGIS.Desktop.Editing.EditOperation();

op.Name = "Create my feature";
// NEED TO UPDATE some of myTemplate default attributes here

op.Create(myTemplate, myGeometry); op.Execute();

When creating a feature in ArcGIS Pro, one can open an active template pane to modify default values for features to be created with this template. Can this be done via API ?

I tried to leverage myTemplate.Inspector to get the Inspector that should contain the associated template values (as per the doc) but it is set to null . I guess I do not know how to use the API in this case. Any advise, code snippets will be appreciated. Thanks

0 Kudos
1 Solution

Accepted Solutions
NarelleChedzey
Esri Contributor

Hi Serguei, 

If you are retrieving a template that is not active, you need to activate that template before the inspector object is available.   Here is some sample code

var map = MapView.Active?.Map;
if (map == null)
  return;

var myTemplate = map.FindLayers("testPoints").FirstOrDefault()?.GetTemplate("testPoints");
if (myTemplate == null)
  return;

// activate the template
myTemplate.ActivateDefaultToolAsync();

// retrieve the inspector
var insp = myTemplate.Inspector;

// modify fields
insp["field1"] = value1;

// perform the edit operation

Thanks

Narelle

View solution in original post

2 Replies
NarelleChedzey
Esri Contributor

Hi Serguei, 

If you are retrieving a template that is not active, you need to activate that template before the inspector object is available.   Here is some sample code

var map = MapView.Active?.Map;
if (map == null)
  return;

var myTemplate = map.FindLayers("testPoints").FirstOrDefault()?.GetTemplate("testPoints");
if (myTemplate == null)
  return;

// activate the template
myTemplate.ActivateDefaultToolAsync();

// retrieve the inspector
var insp = myTemplate.Inspector;

// modify fields
insp["field1"] = value1;

// perform the edit operation

Thanks

Narelle

SergueiSokolov
New Contributor III

Hi Narene

This worked. I appreciate your help

0 Kudos