<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Set Environment to Current Extent in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/set-environment-to-current-extent/m-p/174676#M13450</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I found the following code on a previous forum and thought I could use it to set my env.extent:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;--------------------------------------------------------&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;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&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;SPAN&gt;--------------------------------------------------------&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;This works well and shows me the extent of my current map extent.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;--------------------------------------------------------&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;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"&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;SPAN&gt;--------------------------------------------------------&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is incorrect and gives me an error (Runtime error &amp;lt;type 'exceptions.RuntimeError'&amp;gt;: UNKNOWN).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have clearly done something wrong here. Am I on the right path or way off target here?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for any help.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Julian.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 12 Jun 2012 05:49:03 GMT</pubDate>
    <dc:creator>JulianInskip</dc:creator>
    <dc:date>2012-06-12T05:49:03Z</dc:date>
    <item>
      <title>Set Environment to Current Extent</title>
      <link>https://community.esri.com/t5/python-questions/set-environment-to-current-extent/m-p/174676#M13450</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I found the following code on a previous forum and thought I could use it to set my env.extent:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;--------------------------------------------------------&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;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&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;SPAN&gt;--------------------------------------------------------&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;This works well and shows me the extent of my current map extent.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;--------------------------------------------------------&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;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"&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;SPAN&gt;--------------------------------------------------------&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is incorrect and gives me an error (Runtime error &amp;lt;type 'exceptions.RuntimeError'&amp;gt;: UNKNOWN).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have clearly done something wrong here. Am I on the right path or way off target here?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for any help.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Julian.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Jun 2012 05:49:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/set-environment-to-current-extent/m-p/174676#M13450</guid>
      <dc:creator>JulianInskip</dc:creator>
      <dc:date>2012-06-12T05:49:03Z</dc:date>
    </item>
    <item>
      <title>Re: Set Environment to Current Extent</title>
      <link>https://community.esri.com/t5/python-questions/set-environment-to-current-extent/m-p/174677#M13451</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Try to pass the extent object from data frame to environment setting.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;This code works for me:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;arcpy.env.extent = DF.extent&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Jun 2012 06:26:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/set-environment-to-current-extent/m-p/174677#M13451</guid>
      <dc:creator>MarcinGasior</dc:creator>
      <dc:date>2012-06-12T06:26:10Z</dc:date>
    </item>
    <item>
      <title>Re: Set Environment to Current Extent</title>
      <link>https://community.esri.com/t5/python-questions/set-environment-to-current-extent/m-p/174678#M13452</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Set extent as:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;arcpy.env.extent = DF.extent&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Jun 2012 06:29:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/set-environment-to-current-extent/m-p/174678#M13452</guid>
      <dc:creator>NobbirAhmed</dc:creator>
      <dc:date>2012-06-12T06:29:13Z</dc:date>
    </item>
    <item>
      <title>Re: Set Environment to Current Extent</title>
      <link>https://community.esri.com/t5/python-questions/set-environment-to-current-extent/m-p/174679#M13453</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;WOW, that was an exceptionally fast reply. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks Marcin and Nobbir, your replies worked and tool is working brilliantly now.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Jun 2012 06:48:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/set-environment-to-current-extent/m-p/174679#M13453</guid>
      <dc:creator>JulianInskip</dc:creator>
      <dc:date>2012-06-12T06:48:31Z</dc:date>
    </item>
  </channel>
</rss>

