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.
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="keyword token">import</SPAN> pythonaddins
<SPAN class="keyword token">class</SPAN> <SPAN class="token class-name">TabulateSoil</SPAN><SPAN class="punctuation token">(</SPAN>object<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="string token">"""Implementation for Tools_addin.button (Button)"""</SPAN>
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">__init__</SPAN><SPAN class="punctuation token">(</SPAN>self<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
self<SPAN class="punctuation token">.</SPAN>enabled <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN>
self<SPAN class="punctuation token">.</SPAN>checked <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">False</SPAN>
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">onClick</SPAN><SPAN class="punctuation token">(</SPAN>self<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="comment token"># Set current map document</SPAN>
mxd <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>MapDocument<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"CURRENT"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Remove existing "Soil_Tabulate" from TOC</SPAN>
<SPAN class="keyword token">for</SPAN> df <SPAN class="keyword token">in</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>ListDataFrames<SPAN class="punctuation token">(</SPAN>mxd<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">for</SPAN> tbl <SPAN class="keyword token">in</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>ListTableViews<SPAN class="punctuation token">(</SPAN>mxd<SPAN class="punctuation token">,</SPAN><SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN>df<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">if</SPAN> tbl<SPAN class="punctuation token">.</SPAN>name <SPAN class="operator token">==</SPAN> <SPAN class="string token">"Soil_Tabulate"</SPAN><SPAN class="punctuation token">:</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>RemoveTableView<SPAN class="punctuation token">(</SPAN>df<SPAN class="punctuation token">,</SPAN> tbl<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Define parameters</SPAN>
table <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'C:\Users\pchristensen\Documents\ARCGIS\Default.gdb\Soil_Tabulate'</SPAN>
in_table <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'c:\users\pchristensen\Documents\ARCGIS\Default.gdb\Soil_Tabulate'</SPAN>
out_xls <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'C:\Users\pchristensen\Documents\ARCGIS\scratch\Soiltab.xls'</SPAN>
<SPAN class="comment token"># Delete "table"</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>Delete_management<SPAN class="punctuation token">(</SPAN>table<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Run Tabulate Intersection tool against selected parcel polygon</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>TabulateIntersection_analysis<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Parcel Polygon"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"TMS"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"Soil Polys"</SPAN><SPAN class="punctuation token">,</SPAN> r<SPAN class="string token">"C:\Users\pchristensen\Documents\ARCGIS\Default.gdb\Soil_Tabulate"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"MUSYM"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Run Table to Excel</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>Delete_management<SPAN class="punctuation token">(</SPAN>out_xls<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>TableToExcel_conversion<SPAN class="punctuation token">(</SPAN>in_table<SPAN class="punctuation token">,</SPAN>out_xls<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">del</SPAN> table
<SPAN class="keyword token">del</SPAN> in_table
<SPAN class="keyword token">del</SPAN> out_xls
<SPAN class="keyword token">del</SPAN> mxd
<SPAN class="keyword token">pass</SPAN>
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>