ArcGIS Pro 2.9.
i have a script that creates a cursor on a layer in Pro. Then a for loop to iterate through each of the items in the cursor. Then I am exporting each project that satisfies the If statement to a PDF. My issue is that I only want one project at a time to show up on the export. Almost like a definition query inside of the results of the if statement. If that makes sense.
The main project is centered, but there are surrounding projects that still appear on the PDF. That main project is the only one that I want to show up on the PDF. And then I have dynamic text set up to reflect that project. However, multiple projects are showing up on the export, therefore my dynamic text is going wild showing all of the features from the layout.
import arcpy
# Parameters
#name of the projects layer in the layout
Projects = 'Proposed Water Project'
#name of the Project Name field in the projects layer
name_field = 'ProjectName'
#name of the WBS# field in the projects layer
wbs_field = "WBS_Number"
#name of the district field in the projects layer
district_field = "District"
#name of the total length field in the projects layer
length_field = 'Total_Length'
#name of the map frame housing the map
main_frame_name = 'Map Frame'
#name of your layout in Pro
template_name = 'Water WOS Layout'
#name of the layout element housing the "title"
title_textbox_name = 'PAGE NUMBER'
#name of the output folder
output_folder = [removed]
# Find all the layout elements
#setting a variable for the ArcGIS Pro project file
aprx = arcpy.mp.ArcGISProject [removed]
#setting a variable to create a list of the layouts in the project
layout = aprx.listLayouts(template_name)[0]
#setting a variable to create a list of elements in the map frame
main_frame = layout.listElements('MapFrame_Element', main_frame_name)[0]
#setting a variable to create a list of text elements in the map frame
title_textbox = layout.listElements('Text_Element', title_textbox_name)[0]
# Define the cursor for the projects and loop through them
cursor = arcpy.da.SearchCursor(Projects, ['SHAPE@', name_field, wbs_field, district_field, length_field])
for map_number, Projects in enumerate(cursor):
# Export the PDF using the following format WOS-Project Name-WBS Number-District
outname = output_folder + str(Projects[1]) + '-' + str(Projects[2]) + '-' + str(Projects[3])
#If the total length of the project is less than 900 feet, the project will be exported using 75 padding at the
if Projects[4] < 900:
extent = Projects[0].extent
padding = 75
new_extent = arcpy.Extent(extent.XMin - padding,
extent.YMin - padding,
extent.XMax + padding,
extent.YMax + padding,
None, None, None, None,
extent.spatialReference)
main_frame.camera.heading = 0
main_frame.camera.setExtent(new_extent)
main_frame.camera.scale = 600
layout.exportToPDF(outname)
print("The project that was just exported in Step 1 was: A) Project Name: " + str(Projects[1]) + " B) WBS Number: " + str(Projects[2]) + " C) District: " + str(Projects[3]))
else:
print("This project was not exported in Step 1 was: A) Project Name: " + str(Projects[1]) + " B) WBS Number: " + str(Projects[2]) + " C) District: " + str(Projects[3]))
print("This message concludes the script execution.")
del cursor