I have a python script that complies several pdf documents (exported from ArcMap) into a map book. The first page uses a pdf which is exported from a mxd that has dynamic text for the date. The script does all the exporting and ordering of pages, so the .mxd never actually opens to update the dynamic text. Right now, I have to open the title page mxd and close it (to update the dynamic text) and then run the script. Any way to skip that step to update the dynamic text?
Thanks for any help!
I'm surprised that the dynamic text doesn't update before exporting - it should.
For example, the following script updates dynamic text (current time) between exports:
import arcpy mxd = arcpy.mapping.MapDocument(r'C:/junk/time_test.mxd') arcpy.mapping.ExportToPDF(mxd, r"C:/junk/time_test1.pdf") #comment on 2nd run #arcpy.mapping.ExportToPDF(mxd, r"C:/junk/time_test2.pdf") #uncomment on 2nd run del mxd
I suppose I'm confused by this statement: "The script does all the exporting and ordering of pages, so the .mxd never actually opens to update the dynamic text." Can you post your script?
This morning it worked...however I deleted the old, final output pdf. I am sure in the past, the export will overwrite the old pdf, but yesterday it was showing the date from the previous time I ran it. Not sure if that was the reason.
import arcpy
mxd = arcpy.mapping.MapDocument (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYT.mxd")
arcpy.mapping.ExportToPDF (mxd, "C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYT.pdf")
del mxd
mxd = arcpy.mapping.MapDocument (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYBLANK.mxd")
arcpy.mapping.ExportToPDF (mxd, "C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYBLANK.pdf")
del mxd
mxd = arcpy.mapping.MapDocument (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYD.mxd")
arcpy.mapping.ExportToPDF (mxd, "C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYD.pdf")
del mxd
mxd = arcpy.mapping.MapDocument (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYBACK.mxd")
arcpy.mapping.ExportToPDF (mxd, "C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYBACK.pdf")
del mxd
mxd = arcpy.mapping.MapDocument (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYL.mxd")
mxd.dataDrivenPages.exportToPDF ("C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYL.pdf","ALL","","PDF_MULTIPLE_FILES_PAGE_INDEX",600)
del mxd
mxd = arcpy.mapping.MapDocument (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYR.mxd")
mxd.dataDrivenPages.exportToPDF ("C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYR.pdf","ALL","","PDF_MULTIPLE_FILES_PAGE_INDEX",600)
del mxd
PDF = arcpy.mapping.PDFDocumentCreate (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORY.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYT.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYBLANK.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYD.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYL_1.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYR_1.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYL_2.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYR_2.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYL_3.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYR_3.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYL_4.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYR_4.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYL_5.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYR_5.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYL_6.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYR_6.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYL_7.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYR_7.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYL_8.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYR_8.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYL_9.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYR_9.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYL_10.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYR_10.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYL_11.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYR_11.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYL_12.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYR_12.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYL_13.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYR_13.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYL_14.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYR_14.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYL_15.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYR_15.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYL_16.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYR_16.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYL_17.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYR_17.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYL_18.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYR_18.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYL_19.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYR_19.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYL_20.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYR_20.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYBLANK.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYBLANK.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYBLANK.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYBLANK.pdf")
PDF.appendPages (r"C:\MITCHELL COUNTY GIS\RURAL DIRECTORY\RURAL DIRECTORYBACK.pdf")
PDF.updateDocProperties
PDF.saveAndClose
del PDF
I know this is probably ancient history for you, but I have this exact problem. When i run the ExportToPDF code my Dynamic Text is not updated. I have the "Document Path" on my map, and it still says the date from the last time the MXD was opened on it no matter how many times i run the code.
Even more ancient at this point... But I found this thread having a similar problem. My solution was to loop through text elements containing "<dyn" and setting the visibility to false then true again, that updated the current date field that I was interested in. (This was in ArcGIS Pro 2.8.2)