Last active
October 23, 2017 08:04
-
-
Save AlexArcPy/bf0f1702d6b0d3840f43442a2d5ef5c6 to your computer and use it in GitHub Desktop.
Execute a tool on an ArcMap toolbar from Python script tool in open ArcMap session
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#based on | |
#https://gis.stackexchange.com/questions/252950/how-can-i-call-a-net-c-tool-i-e-a-dll-file-from-a-model-workflow-or-a-py | |
import arcpy | |
import sys | |
from comtypes.client import GetModule, CreateObject | |
#path where snippets102.py module is stored | |
sys.path.append(r'C:\GIS\arcobjects') | |
import snippets102 | |
esriFramework = GetModule(r"C:\Program Files (x86)\ArcGIS\Desktop10.5\com\esriFramework.olb") | |
esriSystem = GetModule(r"C:\Program Files (x86)\ArcGIS\Desktop10.5\com\esriSystem.olb") | |
#access the current application and the map document open | |
pApp = CreateObject(esriFramework.AppROT, interface=esriFramework.IAppROT) | |
pDoc = pApp.Item(0).Document.QueryInterface(esriFramework.IDocument) | |
#access the commands interface | |
pCmdBars = pDoc.CommandBars.QueryInterface(esriFramework.ICommandBars) | |
#get uid of Full extent button | |
uid = CreateObject(esriSystem.UID, interface=esriSystem.IUID) | |
#full list of tools UIDs | |
#http://edndoc.esri.com/arcobjects/9.2/NET/858a508c-b771-467c-81e6-c6aa72d88f9c.htm | |
uid.Value = "{0830FB35-7EE6-11D0-87EC-080009EC732A}" | |
#find and execute the tool | |
cmdItem = pCmdBars.Find(uid) | |
cmdItem.Execute() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks Alexey for this great pair of examples. In order to complete the set, how about an example of calling a tool on custom Python add-in in ArcMap (from within the code behind a second custom Python add-in that is)?