I'm pretty new to ArcPy and am having with what is probably a fairly simple task. I'm trying to change the fitting strategy of a legend in a layout called "Test_Layout", and then change the font size of all elements in the legend to 8. Here is my code so far:
aprx = arcpy.mp.ArcGISProject("CURRENT")
lyt = aprx.listLayouts("Test_Layout")
leg = lyt.listElements("LEGEND_ELEMENT")
leg.fittingStrategy = "AdjustFrame"
for elm in leg.items:
fontSize = 8
Is anyone able to tell me what I'm doing wrong?
Thanks in advance!
You can use element height and width to change the font size and legend size since LegendItem does not have fontSize property.
.... leg.fittingStrategy = "AdjustColumnsAndFont" print(leg.elementHeight, leg.elementWidth) 40.57 75.59 leg.elementHeight = 20 leg.elementWidth = 40
This is the reference link for LegendElement::
Please give a like if helpful and Accept as Solution if it's answered your query.
I was pulled onto some other projects and have only just gotten back to this thread!
I tried the supplied code, however while I observed the fitting strategy set to "Adjust Columns and Font", and the legend size changes to 40w and 20h, neither the legend size changes, nor do any of the font sizes seem to change. Am I doing something wrong?
I am sure this has been uttered many times before on these forums, but does anyone know why on Earth ArcGIS Pro arcpy doesn't have a "fontSize" property?!?!