Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import traceback
- import arcpy
- from arcpy import env
- ## ARGUMENTS
- # argv[1] = input table/feature class path
- # argv[2] = input old field name
- # argv[3] = input new field name
- path = sys.argv[1]
- oldFieldName = sys.argv[2]
- newFieldName = sys.argv[3]
- env.overwriteOutput = True
- fields = arcpy.ListFields(path)
- for field in fields:
- if field.aliasName == oldFieldName:
- if not oldFieldName == newFieldName:
- fieldType = field.type
- # Add new field
- arcpy.AddField_management(path, newFieldName, fieldType)
- #Calculates the new field based on old field values
- arcpy.CalculateField_management(path, newFieldName, "!"+oldFieldName+"!", "PYTHON", "")
- # Delete the old field (if necessary)
- arcpy.DeleteField_management(path, oldFieldName)
- if fieldInfo.getFieldName(index)=="status":
- # Process: Add Field
- arcpy.AddField_management(layer, "stat", "TEXT", "", "", "50", "", "NULLABLE", "NON_REQUIRED", "")
- # Process: Calculate Field
- arcpy.CalculateField_management(layer, "stat", "!status!", "PYTHON_9.3", "")
- # Process: Delete Field
- arcpy.DeleteField_management(layer, "status")
Add Comment
Please, Sign In to add comment