I am looking to create a button that when clicked, clears feature classes and tables created from another tool. I set up the button and installed it but every time I add it to the map with a toolbar it will come up as "missing" and I don't know why. Does it have something to do with needing to define more in the code? This is the first part of what I have:
import arcpy
import pythonaddins
arcpy.env.workspace = "E:/GIS/File_Organization/Data/Sinks/Sinks.gdb"
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd,"*")[0]
class ClicktoClearAll(object):
"""Implementation for ClearButton2_addin.button (Button)"""
def __init__(self):
self.enabled = True
self.checked = False
def onClick(self):
if arcpy.Exists("E:/GIS/File_Organization/Data/Sources/Sources.gdb/Selected_Source1"):
arcpy.Delete_management("E:/GIS/INTEK_File_Organization/Data/Sources/Sources.gdb/Selected_Source1")
arcpy.AddMessage("First selection has been removed.")
else:
pass
if arcpy.Exists("E:/GIS/File_Organization/Data/Sources/Sources.gdb/Selected_Source2"):
arcpy.Delete_management("E:/GIS/File_Organization/Data/Sources/Sources.gdb/Selected_Source2")
arcpy.AddMessage("Second selection has been removed.")
else:
pass
if arcpy.Exists("E:/GIS/File_Organization/Data/Sources/Sources.gdb/Selected_Source3"):
arcpy.Delete_management("E:/GIS/File_Organization/Data/Sources/Sources.gdb/Selected_Source3")
arcpy.AddMessage("Third selection has been removed.")
else:
pass
1 Answer 1
You have an indent error with your second pass
. fix the indention after your else
and the toolbar should work.
I've found that finding errors with custom toolbars can be tricky. I suggest testing them a few lines at a time so that you can have a clear understanding of where they fail when they fail. Go slow. Also note that if your python window in ArcGIS is open when you load the toolbar it will display any python errors that arise from your toolbar.
-
wow, worked like a charm! Thank you so much! Weird that these add-ins give you no warning of errors.Daniel Katleman– Daniel Katleman2017年12月15日 19:31:32 +00:00Commented Dec 15, 2017 at 19:31
-
I’m pretty sure it will display the error in the Python window if it is open when the toolbar loads (ie when ArcMap starts).Emil Brundage– Emil Brundage2017年12月15日 19:49:45 +00:00Commented Dec 15, 2017 at 19:49
Explore related questions
See similar questions with these tags.