AnsweredAssumed Answered

Altering field length if field = string

Question asked by ChancellorMerken on Jun 1, 2017
Latest reply on Jun 1, 2017 by ChancellorMerken

Hi All,

 

Im trying to automate a couple of processing at work but Ive hit a brick wall in trying to change the length of a field in a FC.

 

I want to get the script to iterate over all of the FC's in a dataset and all of the fields of that FC to find the string/text fields but I cant seem to ge the alterfield_management correct and its driving me crazy.

I was doing this on empty FCs andI have seen solutions that create a new FC with the same fields but extended length but this isn't a option because I have many domains attached to the many fcs.

 

import arcpy

#Set workspace
arcpy.env.workspace = r'C:\Users\daniel\AppData\Roaming\ESRI\Desktop10.4\ArcCatalog\gdb'

#Loop through feature classes looking for a field that is a string'
fcList = arcpy.ListFeatureClasses() #get a list of feature classes
for fc in fcList:  #loop through feature classes
    fieldList = arcpy.ListFields(fc)  #get a list of fields for each feature class
    for field in fieldList: #loop through each field
        if field.type == 'Text':
            arcpy.AlterField_management(fc, field.name, '', '','','2000')

I only want to edit the field length and not any other feature. Any help/feedback if youve had success would be welcome, thanks!

Outcomes