Skip to main content
deleted 21 characters in body; edited tags; edited title
Source Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

New to scripts, need help with creating Writing Python script tool for Data Driven Pages?

I'm very new to writing my own scripts, learning as I go. First off, what

What I am trying to accomplish is exporting JPEGs with a world file that follow data driven pages. I would like to automate this process as much as possible, creating a tool for it.

The following script I was able to get to work if I am in the mxd file and create a folder previously that I add to the script (this test run I used C:\Data\test\PIC), then run it . Here it is:

    import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
...     mxd.dataDrivenPages.currentPageID = pageNum
...     print "Exporting page {0} of {1}".format(str(mxd.dataDrivenPages.currentPageID), str(mxd.dataDrivenPages.pageCount))
...     arcpy.mapping.ExportToJPEG(mxd, r"C:\Data\test\PIC" + str(pageNum) + ".jpeg",df,df_export_width=1600,df_export_height=1200,world_file=True)
del mxd
del df

Now I'd like to take it a step further, creating a tool. Something with parameters that allow me to pick the folder, the file name,, the width, height, etc. So I did a test with an input for folder and file name. It didn't work, all it did was open up the script in Notepad when it was complete. What

What am I doing wrong? Am

Am I going about this in the right way at least? The

The parameters I added were Folder for 0 and String for 1. Here's the new script I tried when I made it into a tool:

import arcpy

mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]

in_folder = arcpy.GetParameterAsText(0)
file_name = arcpy.GetParameterAsText(1)


for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
...     mxd.dataDrivenPages.currentPageID = pageNum
...     print "Exporting page {0} of {1}".format(str(mxd.dataDrivenPages.currentPageID), str(mxd.dataDrivenPages.pageCount))
...     arcpy.mapping.ExportToJPEG(mxd, in_folder + file_name + str(pageNum) + ".jpeg",df,df_export_width=1600,df_export_height=1200,world_file=True)
del mxd
del df

New to scripts, need help with creating

I'm very new to writing my own scripts, learning as I go. First off, what I am trying to accomplish is exporting JPEGs with a world file that follow data driven pages. I would like to automate this process as much as possible, creating a tool for it.

The following script I was able to get to work if I am in the mxd file and create a folder previously that I add to the script (this test run I used C:\Data\test\PIC), then run it . Here it is:

    import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
...     mxd.dataDrivenPages.currentPageID = pageNum
...     print "Exporting page {0} of {1}".format(str(mxd.dataDrivenPages.currentPageID), str(mxd.dataDrivenPages.pageCount))
...     arcpy.mapping.ExportToJPEG(mxd, r"C:\Data\test\PIC" + str(pageNum) + ".jpeg",df,df_export_width=1600,df_export_height=1200,world_file=True)
del mxd
del df

Now I'd like to take it a step further, creating a tool. Something with parameters that allow me to pick the folder, the file name,, the width, height, etc. So I did a test with an input for folder and file name. It didn't work, all it did was open up the script in Notepad when it was complete. What am I doing wrong? Am I going about this in the right way at least? The parameters I added were Folder for 0 and String for 1. Here's the new script I tried when I made it into a tool:

import arcpy

mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]

in_folder = arcpy.GetParameterAsText(0)
file_name = arcpy.GetParameterAsText(1)


for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
...     mxd.dataDrivenPages.currentPageID = pageNum
...     print "Exporting page {0} of {1}".format(str(mxd.dataDrivenPages.currentPageID), str(mxd.dataDrivenPages.pageCount))
...     arcpy.mapping.ExportToJPEG(mxd, in_folder + file_name + str(pageNum) + ".jpeg",df,df_export_width=1600,df_export_height=1200,world_file=True)
del mxd
del df

Writing Python script tool for Data Driven Pages?

I'm very new to writing my own scripts.

What I am trying to accomplish is exporting JPEGs with a world file that follow data driven pages. I would like to automate this process as much as possible, creating a tool for it.

The following script I was able to get to work if I am in the mxd file and create a folder previously that I add to the script (this test run I used C:\Data\test\PIC), then run it . Here it is:

    import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
...     mxd.dataDrivenPages.currentPageID = pageNum
...     print "Exporting page {0} of {1}".format(str(mxd.dataDrivenPages.currentPageID), str(mxd.dataDrivenPages.pageCount))
...     arcpy.mapping.ExportToJPEG(mxd, r"C:\Data\test\PIC" + str(pageNum) + ".jpeg",df,df_export_width=1600,df_export_height=1200,world_file=True)
del mxd
del df

Now I'd like to take it a step further, creating a tool. Something with parameters that allow me to pick the folder, the file name,, the width, height, etc. So I did a test with an input for folder and file name. It didn't work, all it did was open up the script in Notepad when it was complete.

What am I doing wrong?

Am I going about this in the right way at least?

The parameters I added were Folder for 0 and String for 1. Here's the new script I tried when I made it into a tool:

import arcpy

mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]

in_folder = arcpy.GetParameterAsText(0)
file_name = arcpy.GetParameterAsText(1)


for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
...     mxd.dataDrivenPages.currentPageID = pageNum
...     print "Exporting page {0} of {1}".format(str(mxd.dataDrivenPages.currentPageID), str(mxd.dataDrivenPages.pageCount))
...     arcpy.mapping.ExportToJPEG(mxd, in_folder + file_name + str(pageNum) + ".jpeg",df,df_export_width=1600,df_export_height=1200,world_file=True)
del mxd
del df
Source Link

New to scripts, need help with creating

I'm very new to writing my own scripts, learning as I go. First off, what I am trying to accomplish is exporting JPEGs with a world file that follow data driven pages. I would like to automate this process as much as possible, creating a tool for it.

The following script I was able to get to work if I am in the mxd file and create a folder previously that I add to the script (this test run I used C:\Data\test\PIC), then run it . Here it is:

    import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
...     mxd.dataDrivenPages.currentPageID = pageNum
...     print "Exporting page {0} of {1}".format(str(mxd.dataDrivenPages.currentPageID), str(mxd.dataDrivenPages.pageCount))
...     arcpy.mapping.ExportToJPEG(mxd, r"C:\Data\test\PIC" + str(pageNum) + ".jpeg",df,df_export_width=1600,df_export_height=1200,world_file=True)
del mxd
del df

Now I'd like to take it a step further, creating a tool. Something with parameters that allow me to pick the folder, the file name,, the width, height, etc. So I did a test with an input for folder and file name. It didn't work, all it did was open up the script in Notepad when it was complete. What am I doing wrong? Am I going about this in the right way at least? The parameters I added were Folder for 0 and String for 1. Here's the new script I tried when I made it into a tool:

import arcpy

mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]

in_folder = arcpy.GetParameterAsText(0)
file_name = arcpy.GetParameterAsText(1)


for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
...     mxd.dataDrivenPages.currentPageID = pageNum
...     print "Exporting page {0} of {1}".format(str(mxd.dataDrivenPages.currentPageID), str(mxd.dataDrivenPages.pageCount))
...     arcpy.mapping.ExportToJPEG(mxd, in_folder + file_name + str(pageNum) + ".jpeg",df,df_export_width=1600,df_export_height=1200,world_file=True)
del mxd
del df