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.
-
In ArcObjects it's IApplication.CurrentTool help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/… but no analogue for arcpy exists. There is a slim possibility of invoking ArcObjects from python but without a GUID/CLSID for a python add-in you can't specify it even then.Michael Stimson– Michael Stimson2014年12月02日 04:08:50 +00:00Commented Dec 2, 2014 at 4:08
1 Answer 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.