I need to extract a list of selected objects from several layers to text file. Is there any script or toolbox available?
Since this is the ModelBuilder space, I thought I'd go ahead and provide some code to use with the Calculate Value tool that would do this. This assumes you have model elements named 'Feature layer', 'Field', and 'Output text file'. If 'Feature layer' has a selection active on it, only field values from the selected rows would be written to the text file.
UPDATE added needed trailing new lines and return value
<SPAN class="comment token"># Expression</SPAN> f<SPAN class="punctuation token">(</SPAN>r<SPAN class="string token">"%Feature layer%"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"%Field%"</SPAN><SPAN class="punctuation token">,</SPAN> r<SPAN class="string token">"%Output text file%"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># Code Block</SPAN> <SPAN class="keyword token">def</SPAN> <SPAN class="token function">f</SPAN><SPAN class="punctuation token">(</SPAN>tbl<SPAN class="punctuation token">,</SPAN> field<SPAN class="punctuation token">,</SPAN> textfile<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="comment token"># extract data to a list of text strings (with trailing newlines)</SPAN> lst <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN>tbl<SPAN class="punctuation token">,</SPAN> field<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> rows<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> rows<SPAN class="punctuation token">:</SPAN> lst<SPAN class="punctuation token">.</SPAN>append<SPAN class="punctuation token">(</SPAN>str<SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> chr<SPAN class="punctuation token">(</SPAN><SPAN class="number token">10</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># unique-ize and sort the list</SPAN> lst <SPAN class="operator token">=</SPAN> sorted<SPAN class="punctuation token">(</SPAN>list<SPAN class="punctuation token">(</SPAN>set<SPAN class="punctuation token">(</SPAN>lst<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># write to file</SPAN> <SPAN class="keyword token">with</SPAN> open<SPAN class="punctuation token">(</SPAN>textfile<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"w"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> f<SPAN class="punctuation token">:</SPAN> f<SPAN class="punctuation token">.</SPAN>writelines<SPAN class="punctuation token">(</SPAN>lst<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">return</SPAN> textfile <SPAN class="comment token"># Data Type</SPAN> File <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>
thanks, now it works
Sorry, look above for an update, I modified the code to add the newlines (chr(10)) for you. (Unfortunately you can't use "\n" inside a Calculate Value code block you need to use chr(10) instead.)
thank you
Currently I've got list in 1 row (e.g FairfieldHartfordLitchfieldMiddlesex.....)
is it possible to gel list in separate row for each object?
(e.g Fairfield
Hartford
Litchfield
Middlesex.....)
thanks
You can export the table contents as a text file manually, but there is no script tool that exists. However, the python code for this process does exist, but you will need to code and set up the parameters yourself. The following documentation should help you get started: https://support.esri.com/en/technical-article/000011842
But to extract the contents to text manually, you can follow the steps in the following documentation. http://desktop.arcgis.com/en/arcmap/10.6/manage-data/tables/exporting-tables.htm
Be sure to select the version of ArcMap you are using at the top to ensure the correct steps are provided.
I hope this points you in the right direction.
Los miembros registrados pueden publicar, seguir actualizaciones y más. ¿Nuevo aquí? Regístrate gratis.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.