Inconsistent export to pdf results.

975
2
11-26-2020 09:36 AM
RandyMcGregor1
New Contributor III

I have  a simple python script that updates a scene bookmark for each of 50 map series map bookmarks and exports a layout. I run it for each of 50 map series bookmarks. 

It works fine, but some of the outputs are missing features and I need to redo them. I'm guessing it's going "too fast" and some of the layouts are exporting before the layout has fully drawn all the features. Is there a way to slow it down, or tell it to wait till everything's drawn fully before it exports?

Thank you,

Randy McGregor

 

#
# Export map series and update scene bookmarks.
#
import arcpy, os, sys, time

out_folder = arcpy.GetParameterAsText(0)

p = arcpy.mp.ArcGISProject("CURRENT")
l = p.listLayouts()[0]
#
# Get the scene:
#
for m in p.listMaps():
    
    if m.mapType == 'SCENE':
        s = m
        break
#
# Get the scene frame:
#
for mf in l.listElements('MAPFRAME_ELEMENT'):

    if mf.camera.mode != "MAP":
        sf = mf
        break
#
# Run the map series:
#
if not l.mapSeries is None:
  ms = l.mapSeries
  
  if ms.enabled:
      
    for pageNum in range(1, ms.pageCount + 1):
      ms.currentPageNumber = pageNum
      time.sleep(5)
      pageName = ms.pageRow.STATE_NAME
      arcpy.AddMessage("> "+pageName+"...")
      arcpy.AddMessage("> "+str(pageNum))
      #
      # Find the corresponding scene bookmark:
      #
      for bk in s.listBookmarks():
          
          if bk.name == pageName:
              arcpy.AddMessage("> Zooming to bookmark: "+bk.name+"...")
              sf.zoomToBookmark(bk)
        
      arcpy.AddMessage(out_folder+"\\Election_2020_"+pageName+".pdf")             
      l.exportToPDF(out_folder+"\\Election_2020_"+pageName+".pdf")

 

 

0 Kudos
2 Replies
by Anonymous User
Not applicable

Hi Randy,

without running your code, I'm just guessing the missing outputs (or bookmarks) are dropped out because code to call the exportToPDF method isn't called in the if bk.name== pageName block.

you could experiment with:

if s.listBookmarks(): # check presence of bookmarks
    for bk in s.listBookmarks():
        if bk.name == pageName:
            arcpy.AddMessage("> Zooming to bookmark: "+bk.name+"...")
            sf.zoomToBookmark(bk)
                
            arcpy.AddMessage(out_folder+"\\Election_2020_"+pageName+".pdf") 
            # call exportToPDF here for the bookmark     
            l.exportToPDF(out_folder+"\\Election_2020_"+pageName+".pdf")
        
else: # exportToPDF when there are no bookmarks
    arcpy.AddMessage(out_folder+"\\Election_2020_"+pageName+".pdf")
    l.exportToPDF(out_folder+"\\Election_2020_"+pageName+".pdf")

 

if this isn't working, then perhaps look at the doc about the Result object.

There is an example in there where you can wait for the success signal in a while loop. 

I'm not sure if the zoomToBookmark method returns a result. 

while result.status < 4:
    time.sleep(0.2)

 

Tags (1)
RandyMcGregor1
New Contributor III

Thanks David,

I'll give that a try. Appreciate it.

Randy

0 Kudos