Use the SDK to modify feature templates

2194
2
10-12-2015 01:45 PM
Highlighted
New Contributor III

Hi, I would like to use the SDK to set a value on a field within a feature template. I want the user to be able to enter an ID at the beginning of a job and then in that session all features (in the layers I want) get given that default value as users create new features. Unless there is some other way of doing this in ArcGIS Pro that anyone can think of.

0 Kudos
2 Replies
Highlighted
Esri Contributor

Ben,

please take a look at this editing sample

https://github.com/Esri/arcgis-pro-sdk-community-samples/tree/master/Editing/EventModule

It does attribute changes based on editing events. It might be a good starting point and require only minor tweaking to fit your definition for 'session' and 'job'.

0 Kudos
Highlighted
Occasional Contributor

Ben,

Three ways of doing this (that I can think of)...

One is to listen for the template you want to override being activated. You can listen for its 'IsActive' property becoming true (PropertyChanged) and then update the 'Inspector' property to set the value of the field to what you want it to be.  This override will be automatically cleared as soon as this template is deactivated.  We should probably add an aggregate event such as ArcGIS.Desktop.Editing.Events.ActiveTemplateChanged to simplify this pattern (so you don't have to listen to Property Changed on all the templates).  I'll bring this up for inclusion in 1.2

Another way, is to actually update the layer definition to modify the template when the 'job id' changes, which would make the project dirty (and the job ID would show up in the saved aprx if the user saves).  This approach would require reading the existing layer definition, updating the 'CIMFeatureTemplate''s 'DefaultValues' property and then updating the layer definition (through SetDefinition()) with the updated definition.

A third way would be to listen to ArcGIS.Desktop.Editing.Events.RowCreatedEvent, and in your handler you can modify the attribute of the newly created row, as it is being created.  In this approach you get the event regardless of how the feature was created (not just templates, so copy paste would also come through here).  It is analogous to IObjectClassEvents.OnCreate in ArcMap. 

As you can see each of these three approaches has a different lifetime or scope.

-John Jones

0 Kudos