Guest User

Untitled

a guest
Jan 21st, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. import sys
  2. import traceback
  3. import arcpy
  4. from arcpy import env
  5.  
  6. ## ARGUMENTS
  7. # argv[1] = input table/feature class path
  8. # argv[2] = input old field name
  9. # argv[3] = input new field name
  10.  
  11. path = sys.argv[1]
  12. oldFieldName = sys.argv[2]
  13. newFieldName = sys.argv[3]
  14.  
  15. env.overwriteOutput = True
  16.  
  17. fields = arcpy.ListFields(path)
  18. for field in fields:
  19. if field.aliasName == oldFieldName:
  20. if not oldFieldName == newFieldName:
  21. fieldType = field.type
  22. # Add new field
  23. arcpy.AddField_management(path, newFieldName, fieldType)
  24. #Calculates the new field based on old field values
  25. arcpy.CalculateField_management(path, newFieldName, "!"+oldFieldName+"!", "PYTHON", "")
  26. # Delete the old field (if necessary)
  27. arcpy.DeleteField_management(path, oldFieldName)
  28.  
  29. if fieldInfo.getFieldName(index)=="status":
  30.  
  31. # Process: Add Field
  32. arcpy.AddField_management(layer, "stat", "TEXT", "", "", "50", "", "NULLABLE", "NON_REQUIRED", "")
  33.  
  34. # Process: Calculate Field
  35. arcpy.CalculateField_management(layer, "stat", "!status!", "PYTHON_9.3", "")
  36.  
  37. # Process: Delete Field
  38. arcpy.DeleteField_management(layer, "status")
Add Comment
Please, Sign In to add comment