Exporting Data with Python from ArcMap

4353
5
Jump to solution
04-21-2015 02:11 PM
DavidStafford
New Contributor II

I have been trying to find a way to follow to do the following:

     Create Python code that will prompt to the user in ArcMap to use the selection tool to create a selected set and then automate the export of the selected set to an In_Memory location and then export the data table to a csv.

This should be easy and I have written the the export to csv by borrowing code from just about everyone and also have created the Add-in but can not get the selected set into the processing.  

I am wondering if I need to use it a stand alone in ArcMap and call or if I can create it all together.

0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Esteemed Contributor

​As I said, if the selection is already made, any script or tool will use the selection assuming you are running them within Arcmap.  Standalone scripts require that you make a selection via the methods I proposed earlier...since you already have the export to csv code apparently, so you should be good to go...give it a try

View solution in original post

5 Replies
DanPatterson_Retired
MVP Esteemed Contributor

not sure what you mean...if a selection already exists then only those records will be exported...I am not sure why the selection process needs to be part of the tool...see the syntax for CopyFeatures in the Management toolbox for code snippets...again, only selected records will be selected, if you want them to make an attribute selection etc, see SelectByAttributes and/or SelectByLocation tool script samples

0 Kudos
DavidStafford
New Contributor II

If I am in Arcmap and make a selection with the selection tool I need a way to export only the selection to the csv.  There is no way for me to select by attributes I want an interactive selection.  I need a very basic understanding of ArcMap button for my users sad but true.  On top of that this is on the edge of my understanding as well.

0 Kudos
BlakeTerhune
MVP Regular Contributor

This functionality already exists in the attribute table of the layer you've made the selection.

ArcGIS Help 10.1 - Exporting tables

It will export only the selected features by default. Just choose "Text File" as your format and it is formatted with comma delimiters. If you like, you can just change the file extension to csv in the export dialog before you click OK.

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

​As I said, if the selection is already made, any script or tool will use the selection assuming you are running them within Arcmap.  Standalone scripts require that you make a selection via the methods I proposed earlier...since you already have the export to csv code apparently, so you should be good to go...give it a try

DavidStafford
New Contributor II

After correcting the line of code magic happens thanks for sending in the right direction.

0 Kudos