Is there a way to set the data driven scale from arcpy? Looking at the documentation for the DataDrivenPages
class, it doesn't seem to be accessible from outside of ArcMap. The script I run within the current map document exports the maps as jpgs based on the Name
and Page Number
fields I set, and at the Data Driven Scale
I specified. When I put the same script into a model (with the necessary adjustments made) and run it from ArcCatalog, I get the same result, except the maps are now at Best Fit
scale, which is the default for data driven pages.
2 Answers
To ensure that the correct scale is used (in my case, the scales are valued stored in a field scale_field
), the following code is added to the for
loop which exports all the maps (the input document must have Data Driven Pages Enabled):
#some code here
mxd = arcpy.mapping.MapDocument(inputMapDoc)
df = arcpy.mapping.ListDataFrames(mxd)[0] #using the 1st data frame
for i in range(1, mxd.dataDrivenPages.pageCount + 1):
mxd.dataDrivenPages.currentPageID = i
df.scale = mxd.dataDrivenPages.pageRow.getValue(scale_field)
If you are running the script on a stored mxd you can set the scale properties in the extent tab of the data driven page setup. You can either use your current scale or use a field from the index layer that contains scale values.
-
The Data Driven Scale is set and stored within the mxd, so in theory it should be able to export it from the model at that specified scale. I've gotten a response from ESRI, so I'm going to try that now and post back here. Commented Jul 13, 2012 at 5:40
-
I would be really interested in a solution to this as well. My key issue is when the scales change within a DDP setup and you get wierd scale bars like 1cm=2.35Km instead of 1cm=2km or whatever and I have had to create separate mxd's for each scale. See gis.stackexchange.com/questions/23375/…– GeorgeCCommented Jul 23, 2012 at 1:48
-
@GeorgeC I've added the solution which worked for me, but I'm not sure if it will solve your problem. Have you tried first extracting the scales at
Best Fit
and storing these values in the field, then using my answer below to set the map scale? Commented Jul 26, 2012 at 5:07