1

How can I programmatically switch to a edittemplate in:

ArcMap 9.3:

IEditLayers pEditLayers;
IFeatureLayer pFeatLayer;
IMap pMap = ((IMxDocument)Application.Document).FocusMap;
pEditLayers = (IEditLayers)Editor;
pMap = Editor.Map;
for (int i = 0; i < pMap.LayerCount; i++)
{
    if (pMap.get_Layer(i).Name == "roads")
    {
        pFeatLayer = (IFeatureLayer)pMap.get_Layer(i);
        pEditLayers.SetCurrentLayer(pFeatLayer, SubType);
    }
... 

ArcMap 10: first idea, but it does not work:

IEditTemplate currentTemplate = m_editor.CurrentTemplate;
for (int i = 0; i < m_editor.TemplateCount -1; i++)
      {
        IEditTemplate editTemplate = m_editor.get_Template(i);
        if (editTemplate.Layer.Name == "roads")
        {
          currentTemplate = editTemplate;
        }
...

2 Answers 2

3

You just need to set the template back through IEditor3.CurrentTemplate (in your code snippet, you are only updating the currentTemplate, which is a local variable).

IEditTemplate currentTemplate = m_editor.CurrentTemplate;
for (int i = 0; i < m_editor.TemplateCount - 1; i++)
{
    IEditTemplate editTemplate = m_editor.get_Template(i);
    if (editTemplate.Layer.Name == "roads")
    {
        currentTemplate = editTemplate;
        m_Editor.CurrentTemplate = currentTemplate; //  <----
    }
}
0
1

I've probably been accessing it in a really painful manner, but I loop through the Editor's CurrentTemplate.Layer property by name:

String currentfeature = theEditor.CurrentTemplate.Layer.Name;
String[] curfeature = currentfeature.Split('.'); //to split the version name from the fc
if(curfeature.Length > 1)
{
     if(curfeature[1].Equals("Branch"))
          {
                //do the editor stuff
          }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.