2

I want to process mxd datasources without changing the extent.

When I open the MXD in ArcMap and click full extent, I get 1:214,890, after I save and re-open in ArcMap I get what I saved with.

When I open the MXD with arcpy the scale changes to 1:570,396, so after processing and saving via arcpy it's zoomed further out when reopened in ArcMap.

df = arcpy.mapping.ListDataFrames(mxd)[0]
print df.extent
1

An alternative would be to hard wire the scale into your code before saving the mxd.

mxd = arcpy.mapping.MapDocument("Current")
df = arcpy.mapping.ListDataFrames(mxd)[0]
df.scale = "1:214,890"
arcpy.RefreshActiveView()
mxd.save()
0

Depending on what else you are planning to do in your script there are two approaches that I think would address this:

  1. Use Fixed Scale on the Data Frame tab of the Properties of your data frame before you save in ArcMap:

enter image description here

  1. Set the scale property on your data frame object explicitly within your script:

    df.scale = 214890

Without seeing a code snippet in your question it is hard to advise on why the scale may be changing in your code/configuration. I just ran a test here using ArcGIS 10.2.2 for Desktop where I:

  1. Opened a test.mxd
  2. Set the scale on its only data frame to 1:100,000
  3. Checked the Data Frame tab of the Properties of the data frame to make sure it was set to Automatic
  4. Saved and closed the map
  5. Ran the code below from IDLE

    import arcpy

    mxd = arcpy.mapping.MapDocument(r"C:\temp\test.mxd")

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

    print df.scale

  6. The value printed was:

    100000.0

  • Im wondering why the difference between arcpy and ArcMap in extent when opening. The extent setting was set to automatic. My goal was just to change layer workspace paths and thats it. – Andy Arismendi Sep 26 '14 at 7:41
  • Using 10.0 when I open close with MXD with ArcMap it stays 1:214,890. As soon as I access it with python from an external script using arcpy.mapping.MapDocument and access the first data frame's scale it spits out 1:570,396 and when I call mxd.save() and reopen in ArcMap it changes it. I was hoping to by dynamic about this, not knowing what the scale/extent is, just opening the map changing workspace paths and saving it back keeping everything else the same. – Andy Arismendi Sep 26 '14 at 21:42
  • @AndyArismendi It sounds like when you run my procedure at 10.0 you are observing different software behaviour. If so, this sounds like a bug that was resolved between 10.0 and 10.2.2. – PolyGeo Sep 26 '14 at 21:49
  • It may be so, if it is I'm wondering if there is a work around (without knowing the scale/extent ahead of time)...? I can set it, but just need an alternate way to read it I guess – Andy Arismendi Sep 26 '14 at 22:13
  • If it is a bug then I can think of no workaround to it. I'm assuming that you are actually using ArcGIS Desktop 10.0 SP5. If not, I recommend upgrading to at least that. – PolyGeo Sep 26 '14 at 22:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.