Hi,
So I have a relatively simple script that is basically a complete list of feature classes in a database and I was wondering how you would compare that list of feature classes to the list of records in a table.
The other thing is, if there is a match between the list of feature classes and the table, to have the table populate with the record count of the matching feature class. I have a rough script that has both the list of the feature classes in a database and the list from the table, as well as the counts for each feature class. The other issue is that the names aren't the exact same but are similar.
So I am trying to first figure out how to compare the list of feature classes to the list of records in the table. I think once I can get that then the rest should be relatively simple to do.
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="comment token">#set parameters</SPAN>
inputTable <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'G:\MyThings\Test\NewTest3\StormLoad.gdb\Stormload_Table'</SPAN><SPAN class="comment token">#arcpy.GetParameterAsText(0)</SPAN>
select_databases <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'G:\MyThings\Test\NewTest4\StormLoad.gdb'</SPAN><SPAN class="comment token">#arcpy.GetParamterAsText(1)</SPAN>
<SPAN class="comment token">#select_fields_toUpdate = arcpy.GetParameterAsText(2)</SPAN>
input_value <SPAN class="operator token">=</SPAN> <SPAN class="string token">'2'</SPAN><SPAN class="comment token">#arcpy.GetParameterAsText(3)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> select_databases
<SPAN class="comment token">#Get list of field names</SPAN>
field_names <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>f<SPAN class="punctuation token">.</SPAN>name <SPAN class="keyword token">for</SPAN> f <SPAN class="keyword token">in</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListFields<SPAN class="punctuation token">(</SPAN>inputTable<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token">#Identify feature class and database field name</SPAN>
fcdb_name_field <SPAN class="operator token">=</SPAN> field_names<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token">#Select the field names to populate</SPAN>
select_field_names <SPAN class="operator token">=</SPAN> field_names<SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">]</SPAN>
datasetList <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListDatasets<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'*'</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">'Feature'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#List feature classes</SPAN>
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">fcsInDS</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">for</SPAN> dataset <SPAN class="keyword token">in</SPAN> datasetList<SPAN class="punctuation token">:</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> dataset
fcList <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListFeatureClasses<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">return</SPAN> fcList
fcsInDB <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListFeatureClasses<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
fcs <SPAN class="operator token">=</SPAN> fcsInDS<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> fcsInDB
<SPAN class="keyword token">for</SPAN> fc <SPAN class="keyword token">in</SPAN> fcs<SPAN class="punctuation token">:</SPAN>
fc_ReCount <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetCount_management<SPAN class="punctuation token">(</SPAN>fc<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">'{0} has a record count of {1}'</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>fc<SPAN class="punctuation token">,</SPAN> fc_ReCount<SPAN class="punctuation token">)</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>inputTable<SPAN class="punctuation token">,</SPAN> field_names<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>
<SPAN class="keyword token">if</SPAN> row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">in</SPAN> fc<SPAN class="punctuation token">:</SPAN>
row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> input_value <SPAN class="comment token">#</SPAN>
cursor<SPAN class="punctuation token">.</SPAN>updateRow<SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">)</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>
I also noticed that when it loops through the list of combined lists, that it errors out with the feature classes in the database as either non existent or supported. I tried making a couple of adjustments to this script but it returns errors.
I would greatly appreciate any assistance with this.
-Robert