Set scale in python

16541
12
Jump to solution
07-22-2013 08:25 AM
josesanchez1
New Contributor III
Hi all,

this is my code:

..
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()


it should work, right?

Well, when I open the map in PDF that I have generated and..time after time, I see Scale = 1:8,223, which means that after the Zoom to Layer, the line:

df.scale = 20000 does not work at all!! (df is the DATA FRAME previously created)

Any suggestions?

Thanks in advance.

Jose.
Tags (2)
12 Replies
RobertBorchert
Frequent Contributor III

hee hee layer files is exactly what I have been trying to get away from for well over a decade.

I have actualy been posting this question ever now and then for a long long time.

I have one particular mxd from which I generate .pdf files for one of my clients.   I have 4 levels of visibility for which I want certain features of a feature class to be visible.  so as the scale gets larger more features become visible.

I normally have 5 features that would be to clutterd to show all of them at a small scale.   So i have them in the mxd 4 times and using definition querys make certain features visible.  When I drop below 1:20,000 the first layer goes gray and the second layer is visible with all features from the first and more now visible.  It also then controls lables.

The major issue is when someone suddently wants a larger format product I have to redefine all the scale visibility or even worse when they want a change in labels I need to make that change multiple times for each copy of the attribute.

etc....

0 Kudos
RobertBorchert
Frequent Contributor III

It has to be possible  Your data frame is constantly returning you current scale.

you scroll in and out if is instantly updated.  Also when you put in scale text or scale bar that changes.  so the system has to be constantly quering it.

0 Kudos
RichardKammer
New Contributor II

Try setting the data_frame parameter of the ExportToPDF function to "PAGE_LAYOUT". This will export the layout view in the mxd. If this parameter in not set it will default to the data frame.

arcpy.mapping.ExportToPDF(mxd, dir + "\file.pdf", "PAGE_LAYOUT")

0 Kudos