Hello, I really hope someone can help me. I have been using the same code to export map series for some weeks and today I'm getting an error telling me that my syntax is invalid when exporting ms.
p = arcpy.mp.ArcGISProject("Current")
l = p.listLayouts()[2]
if not l.mapSeries is None:
ms = l.mapSeries
if ms.enabled:
ms = l.mapSeries
indexLyr = ms.indexLayer
arcpy.SelectLayerByAttribute_management(indexLyr, "NEW_SELECTION", "SA = 19 and AMA = 'A'")
print("Exporting SA{} AMA-{}".format(currentSA, currentAMA)
ms.exportToPDF(relpath + "\P19_MapAtlas_FGD_SA19_AMA-A_SCR.pdf", "SELECTED")
File "<string>", line 12
ms.exportToPDF(relpath + "\P19_MapAtlas_FGD_SA19_AMA-A_SCR.pdf", "SELECTED")
^
SyntaxError: invalid syntax
Why is my ms not valid? I've individually checked that each variable is pointing to the correct feature and I've tested the SelectLayerByAttribute as well, working great. It just does not want to export... Any ideas??
Solved! Go to Solution.
Yes, indeed. The issue was simple syntax it turns out, a parentheses missing on the print statement which made the ms.export function fall within the print function. The error threw off my troubleshooting!
/blogs/dan_patterson/2016/08/14/script-formatting so there are line numbers and proper formatting.
what is the value of relpath
Thank you for the tip on formatting Dan Patterson, I knew there was a better way!
The path is OK, and I got the code to work somehow without modifying anything, I simply had to run each line of code on it's own, slightly painful..... If I figure out what happened I'll post my solution.
Also I should mention I'm running within ArcGIS Pro Python Window.
Samantha Griffore you might want to get a python IDE to use so you don't have to do it line-by-line
Yes, indeed. The issue was simple syntax it turns out, a parentheses missing on the print statement which made the ms.export function fall within the print function. The error threw off my troubleshooting!