Hi, I've written a short piece of code that takes a shapefile, copies to a .gdb, adds WKT attributes and outputs as an excel spreadsheet. The code is:
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="keyword token">import</SPAN> os
<SPAN class="comment token">###Get parameters as variables</SPAN>
inputshp <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN>
ouputDest <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN>
outputName <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">###Copy shapefile to feature class in Default.gdb and add a field called WKT</SPAN>
intFC <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>FeatureClassToFeatureClass_conversion<SPAN class="punctuation token">(</SPAN>in_features <SPAN class="operator token">=</SPAN> inputshp<SPAN class="punctuation token">,</SPAN> out_path <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace<SPAN class="punctuation token">,</SPAN> out_name <SPAN class="operator token">=</SPAN> inputshp<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AddField_management<SPAN class="punctuation token">(</SPAN>in_table <SPAN class="operator token">=</SPAN> intFC<SPAN class="punctuation token">,</SPAN> field_name <SPAN class="operator token">=</SPAN> <SPAN class="string token">"WKT"</SPAN><SPAN class="punctuation token">,</SPAN> field_type <SPAN class="operator token">=</SPAN> TEXT<SPAN class="punctuation token">,</SPAN> field_length <SPAN class="operator token">=</SPAN> <SPAN class="number token">100000</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">###Populate WKT column with WKT geometery</SPAN>
<SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>UpdateCursor<SPAN class="punctuation token">(</SPAN>intFC<SPAN class="punctuation token">,</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="string token">"WKT"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"SHAPE@WKT"</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> cursor<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> cursor<SPAN class="punctuation token">:</SPAN>
row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN>
cursor<SPAN class="punctuation token">.</SPAN>updateRow<SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">###Set output folder to output folder as given by user</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> outputDest
<SPAN class="comment token">###Create xls output</SPAN>
TableToExcel_conversion <SPAN class="punctuation token">(</SPAN>intFC<SPAN class="punctuation token">,</SPAN> outputName<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">###Delete intermittent feature class</SPAN>
Delete_management <SPAN class="punctuation token">(</SPAN>intFC<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">"Finished"</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>
Thus is then implemented in a tool with input parameters of: Shapefile, destination folder and excel spreadsheet name. In trying to run the tool however, I keep receiving the error:
Traceback (most recent call last):
File "S:\Works and Infrastructure Services\Infrastructure and Design\Technical Services\Asset Management\Robin\Python\AddWKT.py", line 10, in <module>
intFC = arcpy.FeatureClassToFeatureClass_conversion(in_features = inputshp, out_path = arcpy.env.workspace, out_name = inputshp)
File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\conversion.py", line 1790, in FeatureClassToFeatureClass
raise e
ExecuteError: ERROR 999999: Error executing function.
Failed to execute (FeatureClassToFeatureClass).
I've tried and failed to diagnose this myself- I'm pretty new to python and this is a means to an end but also a learning experience- could anybody tell me what I'm doing wrong here?
Edit: If anyone can give me pointers on how to format a codeblock within this forum that would also be handy!