Select to view content in your preferred language

Programmatically select an edit template?

3144
2
12-19-2009 08:52 AM
GregRieck
Frequent Contributor
Does anyone have an example code on how to select and activate an edit template.

I'd like to be able to programmatically select my line template and have it automatically start an edit sketch from a known point location.

G
0 Kudos
2 Replies
by Anonymous User
Not applicable
You can use the properties on IEditor3 to loop through the templates. Alternatively you can get the templates for a layer via IEditTemplateManager, then set the one you want as IEditor3.CurrentTemplate.

public void GetEditTemplateManager(ESRI.ArcGIS.Carto.ILayer layer)
{
ILayerExtensions layerExtensions;
IEditTemplateManager editTemplateMgr;
layerExtensions = layer as ILayerExtensions;

//Find the EditTemplateManager extension.
for (int j = 0; j < layerExtensions.ExtensionCount; j++)
{
object extension = layerExtensions.get_Extension(j);

if (extension is IEditTemplateManager)
{
editTemplateMgr = extension as IEditTemplateManager;
//Use EditTemplateManager to get information about templates.
}
}
}

Once you set the current template, you can create geometry for new features (either through the edit sketch or your own geometry). You can set feature attributes via the template:

      m_editor.StartOperation();
      IEditTemplate editTemplate = m_editor.CurrentTemplate;

      IFeatureLayer featLayer = editTemplate.Layer as IFeatureLayer;
      IFeatureClass featClass = featLayer.FeatureClass;
      IFeature newFeature = featClass.CreateFeature();
      newFeature.Shape = point;
     
      //Apply default values as stored in the template properties.
      editTemplate.SetDefaultValues(newFeature);
      newFeature.Store();
      m_editor.StopOperation("Create Point");

      //Invalidate the area around the new feature.
      m_editor.Display.Invalidate(newFeature.Extent, true, (short)esriScreenCache.esriAllScreenCaches);

Note: If you want to use the shape constructors with your tool then you'll need to do a bunch of call forwarding to the current shape constructor, which internally drives the sketch. This is all documented in Beta2.
0 Kudos
GregRieck
Frequent Contributor
Thanks Sean,

I guess I was hoping for a simpler solution that didn't involve looping. It would be nice to get the template by calling it's name. Also, I was thinking along the lines of getting it via "ArcMap.Application.Document.CommandBars.Find" but wasn't sure what the GUID would be.

G
0 Kudos