Hello!
So I've got a map series script that looks at two parent datasets with matching WFR_NUM fields and generates a polygon that encompasses both of them. Then, it uses this union polygon (extLayer) as the index layer in the map series itself. The script works fine up until the map series part. No issues when I do it manually in Pro. When I run the script, it will export whatever page it was last set to in the Pro doc without showing the index layer for some reason.
The points and black polygon are the parent datasets, the pink polygon is the extLayer (index layer)
By section 5 I've already updated the geometry of the selected extLayer (index layer) record. Any help here would be appreciated. Please let me know if you need more context. Thank you!
#----------------------------------------------------------------------------------------------------------------------
# 5. Get a list of templates (Layouts) in the project
#----------------------------------------------------------------------------------------------------------------------
# Get an array of "wTemplates" with all the Layouts in the project (templates) used further down to match to Template value in extLayer
waprx = arcpy.mp.ArcGISProject(wfrTemplate)
wTemplates = []
n = 0
for lyt in waprx.listLayouts(): # list the layout templates that are part of the WFR Map series
arcpy.AddMessage(str(n) + ' - ' + f" {lyt.name}")
wTemplates.append(lyt.name)
n += 1
#----------------------------------------------------------------------------------------------------------------------
# 6. Create Output Locations (if needed)
#----------------------------------------------------------------------------------------------------------------------
# Create the full path to the REGIONS folder
regionFolderPath = os.path.join(netPath, "Output", "REGIONS")
# Create the REGIONS folder (and the Output folder if necessary)
os.makedirs(regionFolderPath, exist_ok=True) # wont error out if it already exists
#----------------------------------------------------------------------------------------------------------------------
# 7. Check Template Values, Create WFR Folder, and Run Map Series
#----------------------------------------------------------------------------------------------------------------------
rowCnt = 0 # use to make sure we only process one row
with arcpy.da.UpdateCursor(extLayer, ['WFR_NUM','WFR_REGION','TEMPLATE'],"\"WFR_NUM\" = '{}'".format(wfr_num)) as wfrs:
for obj in wfrs:
if rowCnt > 1: break # Should only work on one row
rowCnt += 1
if obj[2] in wTemplates: # if the template exists, then...
regionFolderPath = os.path.join(netPath, "Output", "REGIONS", "REGION_" + obj[1]) # this variable stores the output path directory (sans wfr folder and \\)
wfrFolderPath = os.path.join(regionFolderPath, obj[0]) # this variable stores the whole output path directory (with wfr folder but without \\)
if not os.path.exists(regionFolderPath):
os.makedirs(regionFolderPath) # creates the Region_# folder if it doesn't exist
arcpy.AddMessage("region folder created at: "+regionFolderPath)
if not os.path.exists(wfrFolderPath):
os.makedirs(wfrFolderPath) # creates the WFR_# folder if it doesn't exist
arcpy.AddMessage("wfr folder created at: "+wfrFolderPath)
mapPath = wfrFolderPath + '\\'# this variable stores the whole output path directory (sans map name)
####### UNDER CONSTRUCTION ###################################################################################################################
p = arcpy.mp.ArcGISProject(wfrTemplate)
l = p.listLayouts(obj[2])[0] # looks at the templates (layouts) again and grabs the first one that matches the template value in the index layer
print("The value of l (selected layout template) is:", l.name) # this works
if not l.mapSeries is None:
ms = l.mapSeries
if ms.enabled:
ms.refresh()
indexLyr = ms.indexLayer
print("The value of wIndexLyr is:", indexLyr.name) # just making sure its looking at the right layer, it is
arcpy.SelectLayerByAttribute_management(indexLyr, "CLEAR_SELECTION") # clear the current selection (just in case?)
arcpy.SelectLayerByAttribute_management(indexLyr, "NEW_SELECTION", "WFR_NUM = '033-50-003'") # hard coded for now, will need to be changed later
#arcpy.SelectLayerByAttribute_management(indexLyr, "NEW_SELECTION", "\"WFR_NUM\" = '{}'".format(wfr_num))
selectedCount = int(arcpy.GetCount_management(indexLyr).getOutput(0)) # shows that one record in the indexLyr is selected
print("Number of selected features:", selectedCount)
ms.refresh()
ms.exportToPDF(mapPath + "\\Ex3_SelectedFeatures.pdf", "SELECTED", resolution=300)
arcpy.AddMessage("WFR map created at: "+ mapPath + obj[0] + '_WFR_map.pdf')
else:
arcpy.AddMessage('Error! ' + obj[0] + 'might be specifying a template that is not recognized. Please assign template value to WFR layer')
#----------------------------------------------------------------------------------------------------------------------
# arcpy.AddMessage Processing Details
#----------------------------------------------------------------------------------------------------------------------
# Get Time Elapsed and rows processed
ts2 = time.time()
arcpy.AddMessage('time elapsed: ' + "{:.4f}".format(ts2-ts1) + ' seconds')
arcpy.AddMessage('rows processed: ' + "{:,}".format(rowCnt))
exit()