Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

Many thanks

share|improve this question
ref_num = arcpy.GetParameterAsText(0) is a string. If you want int, you have to convert it with int(). – Tomek Oct 22 '12 at 13:15
@Tomek Thanks I have tried that and get 'PageLayoutObject: Error in SetDataDrivenPageID' – Matt Oct 22 '12 at 13:21
It might be a bit messy to have to add another variable in here, but consider creating ref_num_int = int(ref_num) and then mxd.dataDrivenPages.currentPageID = ref_num_int. – Cindy Williams-Jayakumar Oct 23 '12 at 5:40
I had a similar issue a while back, had a string num_string of numbers separated by ; stored as strings, and casting to int did not work. I had to eventually use map(int, num_string.split(";")) to get the numbers recognised as actual integers. Though since you only need the one value, it would be silly to put it in a list. It seems like something else is wrong. – Cindy Williams-Jayakumar Oct 23 '12 at 8:31
What Data Type is input value? How is it called in Arc: text, double, long? If it is double then use int(float(ref_num)). – Tomek Oct 23 '12 at 9:57

I can get a single page with this. You can work back your string names.

import arcpy

arcpy.env.overwriteOutput = True

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

input_number_as_string = arcpy.GetParameterAsText(0)  
if int(input_number_as_string) in range(1, mxd.dataDrivenPages.pageCount + 1):
    ref_num = int(input_number_as_string)
    arcpy.AddMessage("Number entered is out of range. Please contact GIS Dept.")

mxd.dataDrivenPages.currentPageID = ref_num
arcpy.AddMessage("reference number is set : " + str(ref_num))

    arcpy.mapping.ExportToJPEG(mxd, r"C:\Temp\BMS_Page" + str(pageNum) + ".jpg")
    arcpy.addMessage("Cannot print this page. EEEEEEK!")

del mxd
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.