Select to view content in your preferred language

Aliases are not changing

613
10
Jump to solution
06-20-2024 08:28 AM
Seyed-MahdySadraddini
Occasional Contributor

I wrote a code to modify field aliases and there are multiple layers, some with great many columns,  which require alias modification.

Below is the main part of the code which is supposed to be responsible for alias modificaiton. The issue is that after the process is run the aliases in on layers tables have not changed and I can't see why that is! 

Layers is a list of layer names in the gdb. The new_alias is to replace the current alias of the columns.

with open(logpath, 'a') as cur:
    for layer in layers:
        layer = os.path.join(gdb, f"{fds}/{layer}")
        print(f'Layer Name: {layer}', end=f'\n{"="*100}\n')
        cur.write(f'\nLayer Name: {layer}\n{"="*100}\n')
        columns = arcpy.ListFields(layer)
        for field in columns:
            if not field.required and len(field.name) > 20:
            new_alias = field.aliasName.replace("_", " ").replace('PCT', '%').replace('plus', '+')

            cur.write(f'Pre-processed Alias: {field.aliasName}\n')
            arcpy.management.AlterField(in_table=layer
                ,field=field.name
                ,new_field_alias=new_alias)
            print(f'Alias: {new_alias}\nField: {field.name}\n{"-" * 50}')
            cur.write(f'Alias: {new_alias}\nField: {field.name}\n{"-" * 50}\n')

Would you please help me on why this is not working. I am using ArcGISPro?

 

Thanks in advance!

0 Kudos
10 Replies
Seyed-MahdySadraddini
Occasional Contributor

I believe I have found the source of inconsistency... hidden in plain sight!! 🙂

The codes above may be working very well both inside and outside ArcGIS environment, including my own original code above. What I was looking at after the runtime finished were the tables of the already existing feature classes, or layers, on the Contents panel in the software. But I believe those shapes/layers are not the original instances of the layers on the GDB which are modified! Hence, I may not see the changes on the tables of those instances; 

I dragged and dropped in the layers again directly from the GDB and those tables show the modified aliases, just as @HaydenWelch mentioned in his/her solution!! 🙂

0 Kudos