Created
November 8, 2013 19:52
-
-
Save ustroetz/7376623 to your computer and use it in GitHub Desktop.
This file contains 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
# Name: Ulrich Stroetz (U102778) | |
# Date: 2/17/2013 | |
# Purpose: Add fields | |
# Import system modules | |
import arcpy | |
# Input Feature Class) | |
inputFC = arcpy.GetParameterAsText(0) | |
# Create list of field names | |
inputString = arcpy.GetParameterAsText(1) | |
fieldListNew = inputString.split(";") | |
fieldType = arcpy.GetParameterAsText(2) | |
fieldListExist = [f.name for f in arcpy.ListFields(inputFC)] | |
# Add fields | |
for fieldName in fieldListNew: | |
# Check if it already exists | |
if fieldName in fieldListExist: | |
arcpy.AddMessage("The field %s already exists and will not be created." % fieldName) | |
# If not, add it | |
else: | |
fieldName_new = arcpy.ValidateFieldName(fieldName) | |
if fieldName_new != fieldName: | |
arcpy.AddMessage(fieldName + " becomes " + fieldName_new) | |
arcpy.AddField_management(inputFC , fieldName_new, fieldType) | |
arcpy.AddMessage("Created field:" + fieldName_new) | |
arcpy.AddMessage ("Process completed") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment