zoom = arcpy.mapping.ListLayers(mxd,cut,"")[0] # we locate cut layer in TOC. cut is a variable df.extent = zoom.getExtent() # Zoom to Layer zoom df.scale = 20000 # we set the scale to 1:20,000 arcpy.RefreshActiveView() arcpy.RefreshTOC() mxd.save()
Solved! Go to Solution.
list2 = [0,6,7,8,9] # we list the positions of the elements that not may appear in this map. for i in list2: lyr = arcpy.mapping.ListLayers(mxd,"","") lyr.visible = False # we turn off these layers. zoom = arcpy.mapping.ListLayers(mxd,cut,"")[0] # we locate cut (Study area extent) in TOC.
df.extent = zoom.getExtent()
arcpy.RefreshActiveView() arcpy.RefreshTOC()
arcpy.mapping.ExportToPDF(mxd, dir + "\FILE.pdf")
It sets the scale properly into ArcMap, but not when it goes into the PDF.arcpy.mapping.ExportToPDF(mxd, dir + "\FILE.pdf")
import arcpy mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] cut = arcpy.GetParameterAsText(0) # from TOC by Default (LAYER). dir = arcpy.GetParameterAsText(1) # folder type list2 = [0,6,7,8,9] # we list the positions of the elements that not may appear in this map. for i in list2: lyr = arcpy.mapping.ListLayers(mxd,"","") lyr.visible = False # we turn off these layers. CUT IS NUMBER 5, SO IT IS NOT AFFECTED HERE zoom = arcpy.mapping.ListLayers(mxd,cut,"")[0] # we locate cut (Study area extent) in TOC. df.extent = zoom.getExtent() # Zoom to Layer df.scale = 20000 # we set the scale of the output to 1:20,000 arcpy.RefreshActiveView() arcpy.RefreshTOC() mxd.save() arcpy.mapping.ExportToPDF(mxd, dir + "\file.pdf") # we export the map into a PDF file.
First, thanks to everybody for considering my issue. then:
1.- What I am trying to do is exporting into a PDF my Layout View using python. The scale of this map may be 1:20.000 (1:20000)
2.- Before executing the script: Data Frame Properties --> Extent : Automatic
3.- Before executing the script: The scale is set to 30000 (purposely) in order to see if the script works or not.
5.- OK, when I run the script, I look at the Map Scale (Data View) and the sequence I see with my own eyes is:
....1:30,000 (good).......1:20,000 (good!).....1:8,223..(not good).
Result: PDF Scale --> 1:8,223
That is all I can say so far.
Jose.
list2 = [0,6,7,8,9] # we list the positions of the elements that not may appear in this map. for i in list2: lyr = arcpy.mapping.ListLayers(mxd,"","") lyr.visible = False # we turn off these layers. zoom = arcpy.mapping.ListLayers(mxd,cut,"")[0] # we locate cut (Study area extent) in TOC.
df.extent = zoom.getExtent()
arcpy.RefreshActiveView() arcpy.RefreshTOC()
I would like to do something along this line and query data frame scale and put it in definition query.
i.e. I would like create an attribute and call it vscale ( visible scale) can be anything this is arbitrary.
I would like to create a definition query as such.
vscale >= CurrentDataFrameScale
So when I am at or above whatever value i have in vscale my feature becomes visible.
I don't think you can combine a definition query and visible scale range with Python like that. You could use that definition query but it would never change the visible scale range in the MXD on its own. I recommend you try using layer files. When you create a layer file, it will save the visible scale range you set (as well as definition queries, symbology, labels, etc). So instead of adding the feature class from a geodatabase, just add it from the layer file and it will already have all that stuff set up. If you want your visible scale range to change, you'd have to save over the layer file with the new visible scale range set.
Your other option would be to run a Python script that checks for a vscale field in all (or certain) layers in the map and sets the visible scale range; it would have nothing to do with a definition query.