1

I would like to read and edit the Extent Values of each Layer in a MXD-file.

My code:

import arcpy
mxd = arcpy.mapping.MapDocument(r"D:\Work\myInFile.mxd")
for lyr in arcpy.mapping.ListLayers(mxd):
 if lyr.isFeatureLayer:
 # read
 print lyr.getExtent
 # write
 lyr.getExtent = ({XMin}, {YMin}, {XMax}, {YMax})
mxd.saveACopy(r"D:\Work\myOutFile.mxd")
del mxd

The getExtent method is described here But I'm not sure whether this is in any way the correct method.

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Sep 13, 2013 at 13:18

2 Answers 2

2

from your code there is no problem listing layers and getting the extent of layers but i dont think writing method is correct. try the following code with Extent method:

import arcpy
arcpy.env.extent = arcpy.Extent(XMin,YMin,XMax,YMax)

i hope it helps you...

answered Oct 2, 2013 at 11:44
0

@KorporalNobbs getExtent is read only.

Il you want zoom on all featureclass you can run

df = arcpy.mapping.ListDataFrames(mxd, "Bloc1")[0] # or ingore name and get the first df
df.zoomToSelectedFeatures()

Extract from latest Desktop Help

This performs the same ArcMap operation as Selection> Zoom To Selected Features. One difference is that if no features are selected, it will zoom to the full extent of all layers. If you want to zoom to the extent of selected features for a specific layer, try using the Layer.getSelectedExtent method.

In addition the result get extent with labelling

answered Dec 14, 2015 at 11:21

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.