0

I have script for exporting separate data driven pages (script tool in a toolbox).

import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
pageNumbers = [4,7,11] #select pages before exporting
    for pageNum in pageNumbers: 
    mxd.dataDrivenPages.currentPageID = pageNum 
    arcpy.mapping.ExportToJPEG(mxd, r"C:\Path" + str(pageNum) + ".jpg")
del mxd

Is it possible to change the page numbers in the brackets without changing the code manually?

I mean, after clicking the link, you will be brought to a window to choose the pages you would like to export. There may be checkboxes drawn next to the page numbers or text boxes with the page numbers.

1

You can use script parameters to do this. Right click on your script in the toolbox and open the properties window. From here open the Parameters tab and add a new parameter with a value type of long, you can label it as you like.

In the Parameter Properties options below change the MultiValue option to 'Yes'.

If you run your script now you will get an input window to enter the required page numbers.

From there you can pull them into your page number list with:

pageNumbers = arcpy.GetParameterAsText(0) 

You can get more information about working with Parameters here

Understanding Script Tool Parameters

  • Thanks. It works. I use parameter GetParameter import arcpy import os mxd = arcpy.mapping.MapDocument("CURRENT") pageNumbers = arcpy.GetParameter(0) splitthreshold = pageNumbers for pageNum in splitthreshold: mxd.dataDrivenPages.currentPageID = int(pageNum) arcpy.AddMessage("Page {0} has been exported".format(pageNum)) arcpy.mapping.ExportToJPEG(mxd, r"C:\Temp\\" +str(pageNum) + ".jpg", resolution=200) del mxd – Jack Mar 3 at 15:17
  • Because when i using the arcpy.GetParameterAsText() function and put number e.g. '25' then the value will be converted to a string with two numbers ('2' and '5') separated by a semicolon. – Jack Mar 3 at 15:45
  • 1
    Glad to hear you got it working. One suggestion is to remove the splitthreshold object. It is just a copy of the pageNumbers list. import arcpy import os mxd = arcpy.mapping.MapDocument("CURRENT") pageNumbers = arcpy.GetParameter(0) for pageNum in pageNumbers: mxd.dataDrivenPages.currentPageID = int(pageNum) arcpy.AddMessage("Page {0} has been exported".format(pageNum)) arcpy.mapping.ExportToJPEG(mxd, r"C:\Temp\\" +str(pageNum) + ".jpg", resolution=200) del mxd – Magus Mar 4 at 12:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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