Select to view content in your preferred language

Allow for control of numeric format in Python stand-alone script

453
1
10-03-2024 06:04 AM
AntoinePrince1805
Occasional Contributor

ESRI should really offer a way to control numeric format (thousand separator, number of decimal, etc.) for DOUBLE, FLOAT, LONG and SHORT values using python stand-alone scripting (no manual manipulation in ArcGIS Pro needed). As of now, I have explored two options :

1. Specifying the scale of the field when creating a new field using the "AddField" function, but I found out that the "scale" and "precision" parameters are ignored when using on a feature class inside a geodatabase.

2. Using the layer CIM to access the numberFormat properties with the following script, but the fieldDescriptions list always return empty. After reading a bit on the problem, this seems more like a feature than a bug (eventhough I don't get why we cannot acces the list in a python script, bu we can in the python command promt, inside ArcGIS Pro).

aprx_path = [PATH_TO_APRX]
aprx = arcpy.mp.ArcGISProject(aprx_path)
map = aprx.listMaps()[0]
lyr = map.listLayers("MyLayer")[0]

lyr_cim = lyr.getDefinition('V3')

for fd in lyr_cim.featureTable.fieldDescriptions:
    fdNumFmt = fd.numberFormat
    fdNumFmt.useSeparator = True
    fdNumFmt.roundingValue = 2

Please, consider upvoting this idea!

Thanks!

1 Comment
HannesZiegler
Status changed to: Needs Clarification

Hi @AntoinePrince1805 , would you be able to provide more details on what your idea is suggesting? It sounds like the idea is to support filed scale/precision in file geodatabases so that you can specify these when using AddField?