Here's the c# code.
When a user selects a layer to edit, I assign a default tool to edit with. If the layer is a line, use the straight sketch command:
IEditLayers editLayers = toolExtension.editor as IEditLayers;
editLayers.SetCurrentLayer(selectedLayer, subtype_number);
IEditTemplateFactory editTemplateFactory = new EditTemplateFactoryClass();
editTemplate = editTemplateFactory.Create(layer.Name, layer);
IFeatureClass s_featureClass = selectedLayer.FeatureClass;
if (s_featureClass.ShapeType == esriGeometryType.esriGeometryPolyline)
{
Guid g = new Guid("{69DAD63E-3B9B-401D-84AE-27A84F720BB2}");// this is the esriEditor.SketchStraightCommand
editTemplate.Tool = g;
}
When the user wants to start adding features, get the geometry type and set the ICommandItem accordingly.
app = ArcMap.Application;
ICommandBars documentBars = app.Document.CommandBars;
UID cmdID = new UIDClass();
cmdID.Value = "esriEditor.PointFeatureTool";
editTemplate = toolExtension.editor.CurrentTemplate;
IFeatureLayer m_flayer = editTemplate.Layer as IFeatureLayer;
IFeatureClass m_fclass = m_flayer.FeatureClass;
if (m_fclass.ShapeType == esriGeometryType.esriGeometryPolyline)
{
cmdID.Value = "esriEditor.LineFeatureTool";
}
if (m_fclass.ShapeType == esriGeometryType.esriGeometryPoint)
{
cmdID.Value = "esriEditor.PointFeatureTool";
}
ICommandItem cmdItem = documentBars.Find(cmdID, false, false);
app.CurrentTool = cmdItem;