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.
import arcpy
import pythonaddins
class TabulateSoil(object):
"""Implementation for Tools_addin.button (Button)"""
def __init__(self):
self.enabled = True
self.checked = False
def onClick(self):
mxd = arcpy.mapping.MapDocument("CURRENT")
for df in arcpy.mapping.ListDataFrames(mxd):
for tbl in arcpy.mapping.ListTableViews(mxd,"",df):
if tbl.name == "Soil_Tabulate":
arcpy.mapping.RemoveTableView(df, tbl)
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'
arcpy.Delete_management(table)
arcpy.TabulateIntersection_analysis("Parcel Polygon","TMS","Soil Polys", r"C:\Users\pchristensen\Documents\ARCGIS\Default.gdb\Soil_Tabulate", "MUSYM")
arcpy.Delete_management(out_xls)
arcpy.TableToExcel_conversion(in_table,out_xls)
del table
del in_table
del out_xls
del mxd
pass