Select to view content in your preferred language

Set Extent not working.

5156
6
02-23-2015 10:56 AM
PROBERT68
Frequent Contributor

I am trying to set the extent of the ArcMap where I want to add the raster to my ArcMap but this does not work...

 

#Set the Scale extent arcpy.Extent(147806,3495023,584371,3899368)

 

 

I have looked at the ArcGIS 10.1 help about this but not sure which one is the correct way to display them .

0 Kudos
6 Replies
JakeSkinner
Esri Esteemed Contributor

Hi Robert,

Arcpy.Extent is an environment variable for geoprocessing tools.  See the following help:

Output Extent (Environment setting)—Help | ArcGIS for Desktop

To update the data frame extent, you will need to use DataFrame class.

PROBERT68
Frequent Contributor

Thank you.

0 Kudos
PROBERT68
Frequent Contributor

Jake Skinner

I tried to set the extent numbers in UTM  but it would not  allow me to... even I set the df as well...

#Set the df to refresh the "Set Extent"

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

arcpy.env.extent ="MAXOF"

newExtent = df.extent

newExtent.XMin, newExtent.YMin =  210000,360000

newExtent.XMax, newExtent.YMax =  550000,400000

df.extent = newExtent

0 Kudos
JakeSkinner
Esri Esteemed Contributor

What coordinate system is your Data Frame set to?  Also, are you executing this code in the Python window within ArcMap?

0 Kudos
PROBERT68
Frequent Contributor

The imagery are set to NAD 1983 UTM Zone 13 N and the  code I wrote are done in Pyscripter

0 Kudos
JakeSkinner
Esri Esteemed Contributor

Since you are running the code in PyScripter, the extent will not update.  You can run the code within ArcMap using the Python window.  Ex:

import arcpy

mxd = arcpy.mapping.MapDocument("CURRENT")

df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
arcpy.env.extent ="MAXOF"
newExtent = df.extent
newExtent.XMin, newExtent.YMin =  210000,360000
newExtent.XMax, newExtent.YMax =  550000,400000
df.extent = newExtent

del mxd

You can update the extent in PyScripter, but you will need to save the MXD.  Once you re-open the MXD, the map will be at the new extent.  Ex:

import arcpy

mxd = arcpy.mapping.MapDocument(r"C:\data\vector\world\Countries.mxd")

df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
arcpy.env.extent ="MAXOF"
newExtent = df.extent
newExtent.XMin, newExtent.YMin =  210000,360000
newExtent.XMax, newExtent.YMax =  550000,400000
df.extent = newExtent
mxd.save()

del mxd
0 Kudos