I'm a novice when it comes to arcpy and am trying to develop a script that will use arcpy.da.walk to inventory our GIS data. As it goes through the folders/gdbs of data that we have, I want it to export a few items to a csv for each feature class (for now I'd be happy with feature class path, filename, spatial reference name and metadata purpose). I've gotten the script to work up until the metadata purpose part. Once I add the lines:
arcpy<SPAN class="punctuation token">.</SPAN>ExportMetadata_conversion<SPAN class="punctuation token">(</SPAN>feature_class<SPAN class="punctuation token">,</SPAN> translatorpath<SPAN class="punctuation token">,</SPAN> xmlfile<SPAN class="punctuation token">)</SPAN>
tree <SPAN class="operator token">=</SPAN> ElementTree<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
tree<SPAN class="punctuation token">.</SPAN>parse<SPAN class="punctuation token">(</SPAN>xmlfile<SPAN class="punctuation token">)</SPAN>
spot <SPAN class="operator token">=</SPAN> tree<SPAN class="punctuation token">.</SPAN>find<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"idinfo/descript/purpose"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
my script does not return anything. Without those lines, I recieve a csv file with feature class path, filename, and spatial reference name, but if I include the lines my csv file is empty. No errors, just empty. My script (included below) is based off of: https://arcpy.wordpress.com/tag/os-walk/ and http://gis.stackexchange.com/questions/34729/creating-table-containing-all-filenames-and-possibly-metadata-in-file-geodatab/34797#3479/.
Any help is greatly appreciated!
EDITED: Some feature classes may not have a spatial reference defined, and many feature classes may not have any metadata associated. I still want these in the csv, but those fields can either be blank or say something along the lines of "No spatial reference defined" and "No metadata purpose defined".
<SPAN class="keyword token">import</SPAN> os
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="keyword token">import</SPAN> csv
<SPAN class="keyword token">from</SPAN> xml<SPAN class="punctuation token">.</SPAN>etree<SPAN class="punctuation token">.</SPAN>ElementTree <SPAN class="keyword token">import</SPAN> ElementTree
<SPAN class="keyword token">from</SPAN> arcpy <SPAN class="keyword token">import</SPAN> env
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">inventory_data</SPAN><SPAN class="punctuation token">(</SPAN>workspace<SPAN class="punctuation token">,</SPAN> datatypes<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="string token">"""
Generates full path names under a catalog tree for all requested
datatype(s).
Parameters:
workspace: string
The top-level workspace that will be used.
datatypes: string | list | tuple
Keyword(s) representing the desired datatypes. A single
datatype can be expressed as a string, otherwise use
a list or tuple. See arcpy.da.Walk documentation
for a full list.
"""</SPAN>
<SPAN class="keyword token">for</SPAN> path<SPAN class="punctuation token">,</SPAN> path_names<SPAN class="punctuation token">,</SPAN> data_names <SPAN class="keyword token">in</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>Walk<SPAN class="punctuation token">(</SPAN>
workspace<SPAN class="punctuation token">,</SPAN> datatype<SPAN class="operator token">=</SPAN>datatypes<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">for</SPAN> data_name <SPAN class="keyword token">in</SPAN> data_names<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">yield</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>path<SPAN class="punctuation token">,</SPAN> data_name<SPAN class="punctuation token">)</SPAN>
AGSHOME <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetInstallInfo<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Desktop"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="string token">"InstallDir"</SPAN><SPAN class="punctuation token">]</SPAN>
translatorpath <SPAN class="operator token">=</SPAN> AGSHOME <SPAN class="operator token">+</SPAN> <SPAN class="string token">"Metadata\\Translator\\ARCGIS2FGDC.xml"</SPAN>
outfile <SPAN class="operator token">=</SPAN> <SPAN class="string token">"C:\\GIS\\Records\\Data Management\\Inventories\\GIS_Data_Inventory_daWalk_function_outputtocsv_descitems_try_sr_meta.csv"</SPAN>
xmlfile <SPAN class="operator token">=</SPAN> <SPAN class="string token">"C:\\GIS\\Records\\Data Management\\Inventories\\TempInventoryError\\daWalk_function_outputtocsv_descitems_try_sr_meta.xml"</SPAN>
<SPAN class="keyword token">with</SPAN> open <SPAN class="punctuation token">(</SPAN>outfile<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'wb'</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> csvfile<SPAN class="punctuation token">:</SPAN>
csvwriter <SPAN class="operator token">=</SPAN> csv<SPAN class="punctuation token">.</SPAN>writer<SPAN class="punctuation token">(</SPAN>csvfile<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> feature_class <SPAN class="keyword token">in</SPAN> inventory_data<SPAN class="punctuation token">(</SPAN>r<SPAN class="string token">"C:\GIS\Data\Natural_Environment\Species_and_Habitats\Habitat_Models"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"FeatureClass"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">try</SPAN><SPAN class="punctuation token">:</SPAN>
desc <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Describe<SPAN class="punctuation token">(</SPAN>feature_class<SPAN class="punctuation token">)</SPAN>
sr <SPAN class="operator token">=</SPAN> desc<SPAN class="punctuation token">.</SPAN>spatialReference
arcpy<SPAN class="punctuation token">.</SPAN>ExportMetadata_conversion<SPAN class="punctuation token">(</SPAN>feature_class<SPAN class="punctuation token">,</SPAN> translatorpath<SPAN class="punctuation token">,</SPAN> xmlfile<SPAN class="punctuation token">)</SPAN>
tree <SPAN class="operator token">=</SPAN> ElementTree<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
tree<SPAN class="punctuation token">.</SPAN>parse<SPAN class="punctuation token">(</SPAN>xmlfile<SPAN class="punctuation token">)</SPAN>
spot <SPAN class="operator token">=</SPAN> tree<SPAN class="punctuation token">.</SPAN>find<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"idinfo/descript/purpose"</SPAN><SPAN class="punctuation token">)</SPAN>
csvwriter<SPAN class="punctuation token">.</SPAN>writerow<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN>desc<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>encode<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'utf-8'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> desc<SPAN class="punctuation token">.</SPAN>file<SPAN class="punctuation token">.</SPAN>encode<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'utf-8'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> desc<SPAN class="punctuation token">.</SPAN>dataType<SPAN class="punctuation token">.</SPAN>encode<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'utf-8'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> sr<SPAN class="punctuation token">.</SPAN>name<SPAN class="punctuation token">.</SPAN>encode<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'utf-8'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> spot<SPAN class="punctuation token">.</SPAN>text<SPAN class="punctuation token">.</SPAN>encode<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'utf-8'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">except</SPAN><SPAN class="punctuation token">:</SPAN>
<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></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
<SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"></SPAN>