2

I have an ArcGIS Python Add-in project with a tool palette that contains a dozen different tools. I would like to be able to change the 'active tool', i.e. the tool that is visible on the toolbar, when a button on the same toolbar is clicked.

The active tool changes when the user selects a tool from the dropdown palette, but I'm not sure if this behaviour can be replicated using Python.

1

To change the active tool in ArcObjects use the CurrentTool property of IApplication object:

public void CurrentTool(IApplication app)
{
    ICommandBars documentBars = app.Document.CommandBars;
    UID cmdID = new UIDClass();
    cmdID.Value = "{B7FA188F-EBE3-11D0-87FE-080009EC732A}";
    ICommandItem cmdItem = documentBars.Find(cmdID, false, false);
    app.CurrentTool = cmdItem;
}

Which uses the UID/CLSID of the command to identify it. To my knowledge Python tools don't have CLSIDs so you can't invoke them this way. Tools written in .net have CLSIDs embedded in them at creation so are subject to this method.

It is possible to use ArcObjects in python, there's a basic discourse here and a more complete post Accessing ArcObjects from Python?. If you can find a way to associate a CLSID/UID with the tool then it is possible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.