Skip to content

Instantly share code, notes, and snippets.

@ragnarheidar
Last active February 10, 2016 09:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ragnarheidar/5bc7b18fed6951db5c7d to your computer and use it in GitHub Desktop.
Save ragnarheidar/5bc7b18fed6951db5c7d to your computer and use it in GitHub Desktop.
A script that uses the arcpy site-package to read the filename of a feature class, create a field called Name and writes the filename as an attribute in the newly created field.
"""
A script that uses the arcpy site-package to read the filename
of a feature class, create a field called Name and wirites the
filename as an attribute in the newly create filed.
"""
import arcpy
from arcpy import env
arcpy.env.workspace = "SOME/PATH"
datasets = arcpy.ListFeatureClasses()
for shape in datasets:
field = "Name"
expression = str(shape[:-17])
expression = '"' + expression + '"'
arcpy.AddField_management(shape, field, "TEXT")
arcpy.CalculateField_management(shape, field, expression, "VB")
print "Done with " + shape[:-4]
print "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment