I'm now learning how to make a button step by step, and I'm having a problem while testing it: the toolbar is loaded successfully, I can click on it but can't zoom to the selected feature, could someone please explain why this is happening?
Thank you!
C:\Users\lenovo\Documents\ArcGIS\AddIns\python_addin_project_Ren
#config.xml
<?xml version="1.0"?>
-<ESRI.Configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.esri.com/Desktop/AddIns">
<Name>Python Addin Demonstration</Name>
<AddInID>{31e63974-b41b-4801-8000-007d0e28e03e}</AddInID>
<Description>带有工具和按钮的 add-in demonstration</Description>
<Version>0.1</Version>
<Image>Images\Bug.png</Image>
<Author>Sherry</Author>
<Company>Great Fir</Company>
<Date>09/21/2022</Date>
-<Targets>
<Target version="10.1" name="Desktop"/>
</Targets>
-<AddIn language="PYTHON" namespace="python_addin_project_Ren_addin" library="python_addin_project_Ren_addin.py">
-<ArcMap>
-<Commands>
-<Button tip="Zoom to Selected Features" message="Zoom to Selected Features" image="Images\Zoom_to_Seleted_Features.png" id="python_addin_project_Ren_addin.button" class="Zoom_to_Selected_Features" category="Python Addin Demonstration" caption="Zoom to Selected Features">
<Help heading="Zoom to Selected Features">Zoom to Selected Features</Help>
</Button>
</Commands>
<Extensions> </Extensions>
-<Toolbars>
-<Toolbar id="python_addin_project_Ren_addin.toolbar" category="Python Addin Demonstration" caption="Toolbar_1" showInitially="true">
-<Items>
<Button refID="python_addin_project_Ren_addin.button"/>
</Items>
</Toolbar>
</Toolbars>
<Menus> </Menus>
</ArcMap>
</AddIn>
</ESRI.Configuration>
C:\Users\lenovo\Documents\ArcGIS\AddIns\Desktop10.1\{31e63974-b41b-4801-8000-007d0e28e03e} --> .esriaddin path
#makeaddin.py
import os
import re
import zipfile
current_path = os.path.dirname(os.path.abspath(__file__))
out_zip_name = os.path.join(current_path,
os.path.basename(current_path) + ".esriaddin")
BACKUP_FILE_PATTERN = re.compile(".*_addin_[0-9]+[.]py$", re.IGNORECASE)
def looks_like_a_backup(filename):
return bool(BACKUP_FILE_PATTERN.match(filename))
with zipfile.ZipFile(out_zip_name, 'w', zipfile.ZIP_DEFLATED) as zip_file:
for filename in ('config.xml', 'README.txt', 'makeaddin.py'):
zip_file.write(os.path.join(current_path, filename), filename)
dirs_to_add = ['Images', 'Install']
for directory in dirs_to_add:
for (path, dirs, files) in os.walk(os.path.join(current_path,
directory)):
archive_path = os.path.relpath(path, current_path)
found_file = False
for file in (f for f in files if not looks_like_a_backup(f)):
archive_file = os.path.join(archive_path, file)
print(archive_file)
zip_file.write(os.path.join(path, file), archive_file)
found_file = True
if not found_file:
zip_file.writestr(os.path.join(archive_path,
'placeholder.txt'),
"(Empty directory)")
#Zoom_to_Seleted_Features.py
# Implementation of OnClick method of Button's class
def onClick(self):
# Get the current map document and the first data frame.
mxd = arcpy.mapping.MapDocument('current')
df = arcpy.mapping.ListDataFrames(mxd)[0]
# Call the zoomToSelectedFeatures() method of the data frame class
df.zoomToSelectedFeatures()
#python_addin_project_Ren_addin.py
#C:\Users\lenovo\Documents\ArcGIS\AddIns\python_addin_project_Ren\Install
import arcpy
import pythonaddins
class Zoom_to_Selected_Features(object):
"""Implementation for python_addin_project_Ren_addin.button (Button)"""
def __init__(self):
self.enabled = True
self.checked = False
def onClick(self):
pass