AnsweredAssumed Answered

Change Current Tool In ArcMap

Question asked by HandsomePete on Dec 26, 2013
Latest reply on Jan 8, 2014 by HandsomePete
While in an edit session, I want to change the current tool to the Straight Segment tool (aka esriEditor.SketchStraightCommand). 

I created a toolbar with two buttons.  When the first button is clicked it starts the edit session, gets a line feature class in the TOC, makes it the current edit layer and edit template. 

When the next button is clicked, I try to set the current tool to the Straight Segment tool using the following code:

editTemplate = btn1.editor.CurrentTemplate;
                IApplication app = ArcMap.Application;
                ESRI.ArcGIS.Framework.ICommandBars commandBars = app.Document.CommandBars;
                ESRI.ArcGIS.esriSystem.UID commandID = new UIDClass();
                commandID.Value = "esriEditor.SketchStraightCommand";
                ICommandItem commandItem = commandBars.Find(commandID, false, false);
                if (commandItem != null)
                    app.CurrentTool = commandItem; //this is the line that sets off the error
            catch (Exception e)

The error message I get is: "System.ArgumentException: Value does not fall within the expected range."

Digging a little deeper in the debugger, I find this in the commandItem Locals window:
commandItem.Action threw and exception of type 'System.Runtime.InteropServices.COMException.'  {"This method cannot be called on built in commands."}

I've been digging around but I'm not sure what this means.  Is it impossible to set the Straight Segment tool as the current tool from an Add-In button or command?