Copy number formats across multiple fields in Fields menu

1232
3
02-05-2021 05:59 AM
Status: Under Consideration
Labels (1)
MattPBr_app
New Contributor II

When going into Attributes Tables>Fields, the Number format can be edited (Numeric, Percentage, Currency, Rate, ...). Each chosen type has plenty of useful options (number of decimal values, show thousands separators, etc...).

In most cases, once a specific setting has been defined, it would apply to many fields.

It would be great to be able to copy a given Number format and be able to apply it to multiple fields afterwards.

3 Comments
LeandraGordon

Yes Please!! Also could we also have a corresponding Arcpy command to do this in a script!

LeandraGordon

I have successfully managed to edit the numberFormats using Python CIM access so it should be possible to do this in a Python Toolbox with the Layer Name and the Field Name as inputs:

e.g:
-----------------------------------------------------------------------------
currentProject = arcpy.mp.ArcGISProject("CURRENT")
currentMap = currentProject.listMaps()[0]              #I think this assumes there is only one map
layers = currentMap.listLayers()


for layer in layers:

lyrCIM = layer.getDefinition('V2')

if layer.name == INPUT_LYR:
      lyrCIM.showPopups = True

      # Modify the display of numeric fields
      for fd in lyrCIM.featureTable.fieldDescriptions:
          if fd.fieldName == INPUT_FIELD:
                fdNumFmt = fd.numberFormat
                fdNumFmt.useSeparator = True  #Use a comma as a thousands separator

layer.setDefinition(lyrCIM)

currentProject.save
---------------------------------------------------------------------------------------------------



JonathanMurphy
Status changed to: Under Consideration