How do I programmatically export a single Data Driven Page to JPEG?

Discussion created by matt_msuk on Oct 22, 2012
Latest reply on Oct 23, 2012 by Wayne_Whitley
I am trying to write a python script to export a individual pages to a jpeg. I am getting the error "PageLayoutObject: Error in SetDataDrivenPageID". Can anyone see where I am going wrong?

import arcpy
import os.path

arcpy.env.overwriteOutput = True

mxd = arcpy.mapping.MapDocument("CURRENT")

ref_num = arcpy.GetParameterAsText(0)  
ref_num_str = str(ref_num)
ref_num_int = int(ref_num)

jobs = r"\\MSUKSERVER\BusinessMan Docs\Jobs"
job_fol = os.path.join(jobs, ref_num_str)
output_jpeg = os.path.join(job_fol, ref_num_str + "_BMS_plan.jpg")

mxd.dataDrivenPages.currentPageID = ref_num_int
arcpy.mapping.ExportToJPEG(mxd, output_jpeg, "PAGE_LAYOUT", 4679, 3308, 400)
arcpy.AddMessage("exported " + ref_num_str + "_BMS_plan")
del mxd