jinskipesri-southafrica-esridist

Set Environment to Current Extent

Discussion created by jinskipesri-southafrica-esridist Employee on Jun 11, 2012
Latest reply on Jun 11, 2012 by jinskipesri-southafrica-esridist
I am trying to set the environment for my output files to my current map extent so that when I run a Select_analysis it only uses the features in the current extent.

I found the following code on a previous forum and thought I could use it to set my env.extent:
--------------------------------------------------------
import arcpy
import arcpy.mapping


## Sets the MXD file
IMXD = arcpy.mapping.MapDocument("CURRENT")
## Sets the Dataframe
DF = arcpy.mapping.ListDataFrames(IMXD, "Layers")[0]

print DF.extent

--------------------------------------------------------
This works well and shows me the extent of my current map extent.

I tried to modify it slightly to use the extent output to set the env.extent so that whenever I run the script it will only use the current extent (I know that this will limit me to only running it in ArcMap with a specific extent)
--------------------------------------------------------
import arcpy
import arcpy.mapping


## Sets the MXD file
IMXD = arcpy.mapping.MapDocument("CURRENT")
## Sets the Dataframe
DF = arcpy.mapping.ListDataFrames(IMXD, "Layers")[0]
arcpy.env.extent = "DF"

--------------------------------------------------------

This is incorrect and gives me an error (Runtime error <type 'exceptions.RuntimeError'>: UNKNOWN).

I have clearly done something wrong here. Am I on the right path or way off target here?

Thanks for any help.
Julian.

Outcomes