我正在按照这里的教程进行操作:http://resources.arcgis.com/en/help/main/10.1/index.html#/button/014p0000001z000000/
我已将代码添加到 .py 文件中,并使用 makeaddin.py 文件和 Test001.esriaddin 文件安装了插件,但当我按下 ArcMap 中的按钮时,什么也没有发生。它应该缩放到所选要素。我有 ArcMap 10.2,并在 ESRI 提供的 Python 插件向导中指明了这一点。在此先感谢您在这件事上提供的任何帮助。代码如下:
import arcpy
import pythonaddins
class ZoomToSelectedFeatures(object):
"""Implementation for Test001_addin.btn1 (Button)"""
def __init__(self):
self.enabled = True
self.checked = False
# 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()
哇!除非我的声誉达到 10 点,否则它不会让我发布图片……
答案1
我认为您需要纠正 onClick 方法的缩进。
class ZoomToSelectedFeatures(object):
"""Implementation for Test001_addin.btn1 (Button)"""
def __init__(self):
self.enabled = True
self.checked = False
# 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()