error in execution sequence

Discussion created by Sycosys on Mar 22, 2012
Latest reply on Mar 22, 2012 by Sycosys

What my code should be doing is zooming to the flow layer THEN Exporting the Group layer rather than exporting the group layer then zooming to Flow..

I am stumped how this is happening out of sequence, anyone have any ideas?

here is the printout from the tool

Buried Systems
Buried Systems\AF - Auxiliary Feedwater
Exporting C://Users//atimpson//Desktop//DDP_TEMP//AF - Auxiliary Feedwater mapbook.pdf.....
Buried Systems\AF - Auxiliary Feedwater\Flow
Buried Systems\AF - Auxiliary Feedwater\Piping
Buried Systems\SA - Auxilary Steam
Exporting C://Users//atimpson//Desktop//DDP_TEMP//SA - Auxilary Steam mapbook.pdf.....
Buried Systems\SA - Auxilary Steam\Flow
Buried Systems\SA - Auxilary Steam\Piping
Buried Systems\CW - Circulating Water
Exporting C://Users//atimpson//Desktop//DDP_TEMP//CW - Circulating Water mapbook.pdf.....
Buried Systems\CW - Circulating Water\Flow
Buried Systems\CW - Circulating Water\Piping
Buried Systems\CA - Compressed Air
Exporting C://Users//atimpson//Desktop//DDP_TEMP//CA - Compressed Air mapbook.pdf.....
Buried Systems\CA - Compressed Air\Flow
Buried Systems\CA - Compressed Air\Piping
Buried Systems\CA - Compressed Air\Abandoned Piping
Buried Systems\CI - Compressed Air Instrumentation
Exporting C://Users//atimpson//Desktop//DDP_TEMP//CI - Compressed Air Instrumentation mapbook.pdf.....
Buried Systems\CI - Compressed Air Instrumentation\Flow
Buried Systems\CI - Compressed Air Instrumentation\Piping

 import arcpy                                                        

arcpy.env.overwriteOutput = True
mxd = arcpy.mapping.MapDocument("CURRENT")
textlist = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT")
#for txt in textlist:                                                
    #if txt.text == r"MAP SUBTITLE":              
        #subtitle = txt                                              

layerlist = arcpy.mapping.ListLayers(mxd)                         

for lyr in layerlist:
 print lyr                                      
 if lyr.longName !=
  if "flow" in
   df = arcpy.mapping.ListDataFrames(mxd)[0]
   arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION")
   df.scale = df.scale * 1.15
   arcpy.SelectLayerByAttribute_management(lyr, "CLEAR_SELECTION")
   del df
  if lyr.visible == False:
   lyr.visible = True   
   #subtitle.text =
   pdfpath = "C://Users//atimpson//Desktop//DDP_TEMP//" + + r" mapbook.pdf"
   print "Exporting " + pdfpath + "....."                     
   arcpy.mapping.ExportToPDF(mxd, pdfpath)             
   lyr.visible = False                                         

del mxd                                                  

print "Done!"