Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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. –  Arabella Oct 23 '12 at 5:40
1  
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. –  Arabella Oct 23 '12 at 8:31
1  
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

1 Answer 1

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)
else:
    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))


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

del mxd
share|improve this answer

Your Answer

 
discard

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.