Hi! I have created a widget that creates a PDF from a web map. It's working beautifully, and now I need to set the scale of the map on the printed PDF to a specific scale. It should be pretty straightforward (df.scale = 6000), but no matter what I do, I get the following error: RuntimeError: DataFrameObject: Error in setting scale value
I've done a lot of searching and tried many different things, but I either get the same error, or it runs but doesn't set the scale.
Here's what I've done (or at least what I remember):
- Run the script with the data frame scale set in the .mxd as automatic and fixed scale (same error)
- Added arcpy.RefreshActiveView()
Below is a piece of my script; the selected point gets centered on the map, and I want it to zoom to a scale of 1:6,000, rather than stay at the scale of the web map. Can anyone help identify what I'm doing wrong? In case you need to know, the map document is in 10.5.1 and Python is v2.
Your assistance is much appreciated! Thanks!
Annina
# analysis
df = arcpy.mapping.ListDataFrames(mxd)[0]
lyr = arcpy.mapping.ListLayers(mxd, "Points")[0]
# Selects the user-created point, zooms the data frame to the selected point, and then unselects the point
# so it doesn't show as teal in the map
arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION")
df.zoomToSelectedFeatures()
df.scale = 6000
arcpy.SelectLayerByAttribute_management(lyr, "CLEAR_SELECTION")
# Removes the user-created point layer from the legend but keeps it in the map
drawn = arcpy.mapping.ListLayoutElements(mxd, "LEGEND_ELEMENT", "Legend")[0]
drawn.removeItem(lyr)
## arcpy.AddMessage("Layer Name: " + lyr.name)
dictResult = PerformAnalysis(lyr, ExcelFileName)