Last active
February 10, 2016 09:07
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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