ArcPy CIM - reorder layout elements?

479
1
06-20-2022 01:26 PM
I_AM_ERROR
Occasional Contributor

Hi All,

Looking for recommended approaches to reorder layout elements in the Contents sidebar using ArcPy CIM. I'm assuming that I can just move elements around by their list index in the Layout definition?

Code_j1t6Xa5h3s.png

Tags (3)
0 Kudos
1 Reply
JohannesLindner
MVP Frequent Contributor

Yes.

This script reverses the order of layout elements in the content pane and in the layout itself:

layout = arcpy.mp.ArcGISProject("current").listLayouts()[0]
cim = layout.getDefinition('V2')
print([e.name for e in cim.elements])  # layout elements from bottom to top
#['Map Frame', 'Scale Bar', 'North Arrow', 'Map Frame 1', 'Table Frame']
cim.elements.reverse()
print([e.name for e in cim.elements])
#['Table Frame', 'Map Frame 1', 'North Arrow', 'Scale Bar', 'Map Frame']
layout.setDefinition(cim)

 

JohannesLindner_0-1655793344149.pngJohannesLindner_1-1655793357482.png

 

 


Have a great day!
Johannes
0 Kudos