Select to view content in your preferred language

List Layouts: how to find out the Layout Number

1193
4
Jump to solution
11-17-2023 02:50 AM
IlkaIllers1
Frequent Contributor

Hello,

I want to export a map series as jpgs and am trying to write a script. However, I am stuck in how to "call" the correct layout. There are 9 layouts in the aprx, however, there used to be more that were deleted. I am trying to find the right one by trial and error going through numbers. This is the code:

aprx = arcpy.mp.ArcGISProject(r"path.aprx")
lyt = aprx.listLayouts()[0]
print(lyt.name)

Is there a way to find out the number/position of the layout? I was thinking of something like that:

aprx = arcpy.mp.ArcGISProject(r"path.aprx")
for lyt in aprx.listLayouts():
    print(lyt.name)
    print(lyt.???)

Is there any property I can put in there to find out which position it has?

Thanks!

0 Kudos
1 Solution

Accepted Solutions
JeffBarrette
Esri Regular Contributor

Hello @IlkaIllers1 .  Position should not matter.  They are sorted in alphabetical order in the Catalog pane but you should reference the layout by name.

for example, lyt = aprx.listLayouts(wildcard='Some Layout Name')[0]

Because it is a list, you still need to specify an index number to return a Layout object from the list but if your wildcard value is unique enough, there should be only one element in the list (with index=0)

Jeff - Layout and arcpy.mp teams

View solution in original post

0 Kudos
4 Replies
JeffBarrette
Esri Regular Contributor

Hello @IlkaIllers1 .  Position should not matter.  They are sorted in alphabetical order in the Catalog pane but you should reference the layout by name.

for example, lyt = aprx.listLayouts(wildcard='Some Layout Name')[0]

Because it is a list, you still need to specify an index number to return a Layout object from the list but if your wildcard value is unique enough, there should be only one element in the list (with index=0)

Jeff - Layout and arcpy.mp teams

0 Kudos
IlkaIllers1
Frequent Contributor

Hi, thanks for your answer. It kept telling me the list index was out of range when it was set to 0... 

0 Kudos
JeffBarrette
Esri Regular Contributor

If you use a wildcard value, you must match the layout name exactly.  It is case sensitive.  You can also use an * in the wildcard.  For example if I have a layout called 'Great Lakes' I can so stuff like:

lyt = p.listLayouts('Great*)[0]

lyt = p.listLayouts('*akes')[0]

lyt = p.listLayouts('*eat*')[0]

0 Kudos
IlkaIllers1
Frequent Contributor

Hello,

thanks. I copied the name from the layout directly, so it shouldn't be an issue. I think this might be connected to several issues I have been having where content can't be renamed/is renamed but is then having issues/reappears after being deleted and similar things. I tried again with a fresh aprx and it worked fine, so I believe this must be related to these issues (I did rename the layout just before trying the arcpy export). Thank you!

0 Kudos