get data from selected features

434
3
07-18-2018 07:56 AM
TanyaMthet
New Contributor

Is it possible to get the attribute values from selected features and export them to an excel file using python?  If so, how do i go about it.

Thank You

0 Kudos
3 Replies
deleted-user-qpvAI3Fo0MKR
Occasional Contributor III

If I understand you correctly, you're wanting to create a selection, and then export the results to .xls.

Here's how I would do it:

# Import libary
import arcpy
from arcpy import env

# Set variables
yourworkspace = "path to your workspace"
yourfeatureclass = "path to your feature class"
outputlocation = "path to your output folder"

arcpy.env.workspace = yourworkspace

# Make Layer
arcpy.MakeFeatureLayer_management (yourfeatureclass, "featureclasslayer")

# Create selection
arcpy.SelectLayerByAttribute_management ("featureclasslayer", "NEW_SELECTION" ["build your selection criteria here"])

# Copy the results of your selection to a new feature class
arcpy.CopyFeatures_management ("featureclasslayer", "yourselectedfeatures")

# Export to Excel
TableToExcel_conversion ("yourselectedfeatures", "yourexcefilename.xls")

# Finish

raise SystemExit(0)

TanyaMthet
New Contributor

Thank you

0 Kudos
deleted-user-qpvAI3Fo0MKR
Occasional Contributor III

You bet. Please let me know if you have any questions and I'll do my best to help.

0 Kudos