I'm on ArcGIS Pro (self-taught) and I am trying to make a batch of layouts for different species occurrence records over the same extent. I have all the XY to Point data as a layer and have been using the display filter to limit which species is shown, then manually exporting the layout, and changing the species again. All other factors are the same, save the species. I want to automate this since I have 80 or so to do (and do this often). Using Map series hasn't worked, since the extent always changes, so I thought I would attempt with arcpy since I know a little bit about python...
Ideally, I want to create a layout for each species, with the same extent, layers, etc, but with a different species selected from the XY to Point layer. I then want to export the layout with the name of the species selected.
This is the code I have so far, and it all seems to work (i.e. it exports a pdf for each, with the layers I can see looking good, and runs without errors) but it has an odd extent, off to the right of the continental U.S., and a North arrow that is not in the layout I am calling. I got the extent values from the extent on the formatted layout/mapframe by looking in properties and copying the values there. Is there a way to edit the extent of the layout?
import arcpy, os
#Project path
aprx = arcpy.mp.ArcGISProject(
r"pathtoproject.aprx")
# Set the name of the XY to Point table
table_name = "ScioSpecies"
# Set the name of the field that contains the class names
class_field = "Species"
#Set a reference to the map view in my project
map_view = aprx.listMaps()[0]
# Get a reference to the layout
layout = aprx.listLayouts()[0]
#Setting up layout/mapframe
map_frame = layout.listElements("MAPFRAME_ELEMENT")[0]
extent = arcpy.Extent(5331425.860609497, -12839586.820429197, -12017230.660916878, 4267200.242417085)
map_frame.camera.setExtent(extent)
class_list = []
with arcpy.da.SearchCursor(table_name, class_field) as cursor:
for row in cursor:
if row[0] not in class_list:
class_list.append(row[0])
#Verify all species are present
print(class_list)
for species in class_list:
arcpy.SelectLayerByAttribute_management(table_name, "NEW_SELECTION", "Species = '{}'".format(species))
layout.exportToJPEG(
r"pathtosavefile{}.jpg".format(species),
resolution=800)