How to change the dynamic text tag for maximum value in a field using Arcpy.mp?

227
3
10-16-2020 11:35 AM
New Contributor II

Hi Everyone: I have successfully produced a map with title, legend and statistics (number, maximum, minimum, mean). I did this within ArcPro through the desktop application, creating a template. Now I want to produce many maps, but only changing the column of data or "field" in the corresponding attribute table. I only having issues with the statistics (number, maximum, minimum, mean) where the field does not change even when the map plots do (so I have the title, legend and the map colors for each polygon on the map updating to the newer column through an earlier command "sym.renderer.classificationField = 'Sheet4.NEI2014v_1'  "  which switched it from the NEI2014v2_ field. This command appears to not impact the text statistics (number, max, min, mean) which are based on the listElements module under "TEXT_ELEMENT".

The dynamic text tag reads as follows: Maximum: <dyn type="table" property="max" mapFrame="Map Frame" mapMemberUri="CIMPATH=map/cb_2018_us_county_500k.xml" isDynamic="true" field="Sheet4.NEI2014v2_" decimalPlaces="2" separator="true"/>

In Arcpy.mp, I am able to print out this text out with:

aprx = arcpy.mp.ArcGISProject(relpath + r'C:/Users/ggrodzinsky/Documents/ArcGIS/Projects/MyProject8/SavedOutput7014.aprx')
m=aprx.listMaps("Map")[0]
l = m.listLayers()[2]
Layout = aprx.listLayouts("Layout")[0]

five=Layout.listElements("TEXT_ELEMENT",'Text 2')[0]

print(five.text)

And it produced:
Maximum: <dyn type="table" property="max" mapFrame="Map Frame" mapMemberUri="CIMPATH=map/cb_2018_us_county_500k.xml" isDynamic="true" field="Sheet4.NEI2014v2_" decimalPlaces="2" separator="true"/>

Don't worry about the above coding, other than this is how I confirmed this is indeed the contents of this Text Element on the Layout I am working on.  What I want to do in my program is change the dynamic text tag so the field changes to a different column of values in the attribute table ("field" is the column title on the attribute table), specifically from "Sheet4.NEI2014v2_" to "Sheet4.NEI2014v_1".  So if I typed "print(five.text) again, it would show field="Sheet.NEI2014v_1" instead in the dynamic text tag.

I searched around and can't find the correct command or coding to have the dynamic text tag change the "field"

It is simply typing in a box in the ArcPro desktop app, but I want to mass produce this through Arcpy.mp (or at least be able to produce a dozen at a time for this case). 

Thanks so much for your input!

Gil

Reply
0 Kudos
3 Replies
Esri Contributor

Hi Gil Grodzinsky,

The text property is a string that is returned, hence you can use the Python string replace function.

five.text = five.text.replace("Sheet4.NEI2014v2_","Sheet4.NEI2014v_1")

print(five.text)

Output:

Maximum: <dyn type="table" property="max" mapFrame="Map Frame" mapMemberUri="CIMPATH=map/cb_2018_us_county_500k.xml" isDynamic="true" field="Sheet4.NEI2014v_1" decimalPlaces="2" separator="true"/>

Hope this helps.

Cheers,

Manish

 

If this answer solved your question or if you found it helpful please mark it accordingly to help others who have the same question.

Cheers,
Manish
New Contributor II

Manish, you are a godsend. It worked like a charm. Thanks so much!

Gil

Esri Contributor

Hi Gil Grodzinsky

Happy to help 🙂 

Glad that it worked, also please dont forget to mark the reply as answered, this will help other users to find it quickly

Have a good day ahead!!

Cheers,

Manish

Cheers,
Manish
Reply
0 Kudos