I have a script that runs the "Tabulate Intersection" tool for me that is assigned to a toolbar button. It works wonderfully.
This is the first script I have created so I apologize if it is not as clean as it can be!
My last step in this map automation, is to open the excel file once it is created instead of me having to navigate all the way to its location in the file explorer just to open it. That takes away the simplicity of just clicking a button and having the desired output.
One option is to just have the saved destination in a folder on my desktop that way it is just two clicks and I am there. But I wanted to first see if there was a way in arcpy to actually open a document in its native program (Excel) for viewing.
"""Implementation for Tools_addin.button (Button)"""
self.enabled = True
self.checked = False
# Set current map document
mxd = arcpy.mapping.MapDocument("CURRENT")
# Remove existing "Soil_Tabulate" from TOC
for df in arcpy.mapping.ListDataFrames(mxd):
for tbl in arcpy.mapping.ListTableViews(mxd,"",df):
if tbl.name == "Soil_Tabulate":
# Define parameters
table = r'C:\Users\pchristensen\Documents\ARCGIS\Default.gdb\Soil_Tabulate'
in_table = r'c:\users\pchristensen\Documents\ARCGIS\Default.gdb\Soil_Tabulate'
out_xls = r'C:\Users\pchristensen\Documents\ARCGIS\scratch\Soiltab.xls'
# Delete "table"
# Run Tabulate Intersection tool against selected parcel polygon
arcpy.TabulateIntersection_analysis("Parcel Polygon","TMS","Soil Polys", r"C:\Users\pchristensen\Documents\ARCGIS\Default.gdb\Soil_Tabulate", "MUSYM")
# Run Table to Excel