I have text elements I'm trying to align in ArcGIS Pro 1.4.1. I want to select all text elements with similar names, i.e., "latlonTableLinexx", where xx is the element number. I guess ideally I'd follow that with the "Align Center" command, aligning to the element at the top (usually element 01).

Probably a simple solution but I didn't find anything in a cursory search of ArcPy for selecting similarly named elements. I've certainly worked with elements in Python, but never asked it to select a group so I can work with them in the ArcGIS Pro layout.


  • 1
    How are you creating a TextElement object for a single text element? – PolyGeo May 25 '17 at 22:14
  • I'm not sure I understand the question. I have a number of similar text elements in each line of the layout (13, in this particular case). So, for all the LatLon text elements (named/numbered sequentially as in my initial post) I want to select them via code rather than in the contents pane, and align them. Maybe that clarifies it? – user97959 May 25 '17 at 22:28
  • 1
    If you need more help than my answer to complete your code to do the aligning to center then ask that as a new question, and in that, as for all coding questions please provide a code snippet that illustrates what you have tried and where you are stuck. – PolyGeo May 25 '17 at 22:58

This code snippet illustrates how to access similarly named text elements using ArcPy of ArcGIS Pro:

import arcpy
aprx = arcpy.mp.ArcGISProject(r"path_to_your_APRX")
lyt = aprx.listLayouts("Layout")[0]
for elm in lyt.listElements("TEXT_ELEMENT","latlonTableLine*"):

listElements returns a list of elements which are of type "TEXT_ELEMENT" and have names starting with "latlonTableLine".

Once you have that you can use a for loop to iterate through it.

  • I already know how to iterate through a list. What I want is all of the similar elements selected in the layout (rather than in code) to be aligned. I'd add an image but I'm still either too new to asking questions or just not bright enough to do that today for some reason. Picture a column of text elements with all of them showing their selection handles. Selecting graphically doesn't always work for various reasons. – user97959 May 25 '17 at 23:05
  • 1
    @user97959 From code you cannot "select" layout elements, you build lists and assign objects to variables. They can be used to perform the alignment but how to do that is another question. – PolyGeo May 25 '17 at 23:07

Not the answer you're looking for? Browse other questions tagged or ask your own question.