I'm just trying to create a tool that zooms in on a layer and then exports the image as PDF, I'll add more functionality later. The code below will run and produce a PDF, but won't zoom to the layer. While running the same basic code in the Python window inexplicably works just fine. I've tried using zoomToSelectedFeatures and definitionQuery, both yield the same result. So now I'm rather lost.
import arcpy, csv, os
pole=arcpy.GetParameterAsText(0)
worksheet=arcpy.GetParameterAsText(1)
out=arcpy.GetParameterAsText(2)+"\_"
mxd=arcpy.mapping.MapDocument("CURRENT")
df=arcpy.mapping.ListDataFrames(mxd)[0]
i=0
worksheet=r'C:\Users\Samuel\worksheet.csv'
with open(worksheet) as f:
for row in csv.reader(f):
i=row[0]
text=row[1]
arcpy.MakeFeatureLayer_management("pole","lyr","FID="+str(i))
arcpy.SelectLayerByAttribute_management("lyr","NEW_SELECTION")
df.zoomToSelectedFeatures()
arcpy.SelectLayerByAttribute_management("lyr","CLEAR_SELECTION")
arcpy.RefreshActiveView()
arcpy.mapping.ExportToPDF(mxd, out+"_pole_"+i,"PAGE_LAYOUT")
break
arcpy.Delete_management("lyr")
arcpy.MakeFeatureLayer_management("pole","lyr","FID="+str(i))