0

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 

This is the error that I keep getting

etrimaille
7,57736 silver badges50 bronze badges
asked Dec 15, 2017 at 14:45

1 Answer 1

2

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.

answered Dec 15, 2017 at 18:19
2
  • wow, worked like a charm! Thank you so much! Weird that these add-ins give you no warning of errors. Commented 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). Commented Dec 15, 2017 at 19:49

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.