<?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 Cant get selected feature to clear? in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/cant-get-selected-feature-to-clear/m-p/427734#M14380</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;So I am fairly new to python scripting, but I have what seems like it should be a fairly simple script that selects an attribute from a layer, zooms to it, and then clears the selection and exports a png of the map. However, the CLEAR_SELECTION function doesn't actually seem to be doing anything, and all the maps the script outputs still have the selected feature highlighted in blue when it is outputted to the png.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;# Import arcpy module
import arcpy



# Set Geoprocessing environments
arcpy.env.workspace = "*****"

##overwrites output
arcpy.env.overwriteOutput = True


#mapDocument
mxd = arcpy.mapping.MapDocument(*******.mxd")

#setting layer variable
addLayer = arcpy.mapping.Layer(********.lyr")


##setting dataset variable
df = arcpy.mapping.ListDataFrames(mxd)[0]

#select layer 
arcpy.SelectLayerByAttribute_management(addLayer, "NEW_SELECTION", ' *********** ')

#set scale
df.scale = 7000000

##adds layer variable to mxd
arcpy.mapping.AddLayer(df, addLayer)


##zooms to layer
df.zoomToSelectedFeatures()


####unselect point
arcpy.SelectLayerByAttribute_management(addLayer,"CLEAR_SELECTION")


##exports current map extent to png
arcpy.mapping.ExportToPNG(mxd,*************,df,df_export_width=550,df_export_height=480)&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 10 Jul 2013 16:06:49 GMT</pubDate>
    <dc:creator>ja3</dc:creator>
    <dc:date>2013-07-10T16:06:49Z</dc:date>
    <item>
      <title>Cant get selected feature to clear?</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/cant-get-selected-feature-to-clear/m-p/427734#M14380</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;So I am fairly new to python scripting, but I have what seems like it should be a fairly simple script that selects an attribute from a layer, zooms to it, and then clears the selection and exports a png of the map. However, the CLEAR_SELECTION function doesn't actually seem to be doing anything, and all the maps the script outputs still have the selected feature highlighted in blue when it is outputted to the png.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;# Import arcpy module
import arcpy



# Set Geoprocessing environments
arcpy.env.workspace = "*****"

##overwrites output
arcpy.env.overwriteOutput = True


#mapDocument
mxd = arcpy.mapping.MapDocument(*******.mxd")

#setting layer variable
addLayer = arcpy.mapping.Layer(********.lyr")


##setting dataset variable
df = arcpy.mapping.ListDataFrames(mxd)[0]

#select layer 
arcpy.SelectLayerByAttribute_management(addLayer, "NEW_SELECTION", ' *********** ')

#set scale
df.scale = 7000000

##adds layer variable to mxd
arcpy.mapping.AddLayer(df, addLayer)


##zooms to layer
df.zoomToSelectedFeatures()


####unselect point
arcpy.SelectLayerByAttribute_management(addLayer,"CLEAR_SELECTION")


##exports current map extent to png
arcpy.mapping.ExportToPNG(mxd,*************,df,df_export_width=550,df_export_height=480)&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Jul 2013 16:06:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/cant-get-selected-feature-to-clear/m-p/427734#M14380</guid>
      <dc:creator>ja3</dc:creator>
      <dc:date>2013-07-10T16:06:49Z</dc:date>
    </item>
    <item>
      <title>Re: Cant get selected feature to clear?</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/cant-get-selected-feature-to-clear/m-p/427735#M14381</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You could try a new selection with an expression you know will return no records.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;something like OBJECTID = 0&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Jul 2013 18:08:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/cant-get-selected-feature-to-clear/m-p/427735#M14381</guid>
      <dc:creator>markdenil</dc:creator>
      <dc:date>2013-07-10T18:08:07Z</dc:date>
    </item>
    <item>
      <title>Re: Cant get selected feature to clear?</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/cant-get-selected-feature-to-clear/m-p/427736#M14382</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Unfortunately that didn't seem to work either&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Jul 2013 18:35:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/cant-get-selected-feature-to-clear/m-p/427736#M14382</guid>
      <dc:creator>ja3</dc:creator>
      <dc:date>2013-07-10T18:35:52Z</dc:date>
    </item>
    <item>
      <title>Re: Cant get selected feature to clear?</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/cant-get-selected-feature-to-clear/m-p/427737#M14383</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Using&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView() &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;after&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(addLayer,"CLEAR_SELECTION")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;would help.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Didn't notice it wasn't there earlier....&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Jul 2013 10:55:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/cant-get-selected-feature-to-clear/m-p/427737#M14383</guid>
      <dc:creator>markdenil</dc:creator>
      <dc:date>2013-07-11T10:55:43Z</dc:date>
    </item>
    <item>
      <title>Re: Cant get selected feature to clear?</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/cant-get-selected-feature-to-clear/m-p/427738#M14384</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Still no luck.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Interestingly, the RemoveLayer command won't work once the layer is added either. There seems to be something wrong with the way I am adding the layer to the mxd&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I finally got it to work, but in a really round-about way.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Import arcpy module
import arcpy



# Set Geoprocessing environments
arcpy.env.workspace = "**************"

##overwrites output
arcpy.env.overwriteOutput = True


#mapDocument
mxd = arcpy.mapping.MapDocument(r"***********************.mxd")

#setting layer variable
nl = arcpy.mapping.Layer(r"*****************************.lyr")

##setting dataset variable
df = arcpy.mapping.ListDataFrames(mxd)[0]

#select layer 
arcpy.SelectLayerByAttribute_management(nl, "NEW_SELECTION", ' "***************" ')

#set scale
df.scale = 7000000

##adds layer variable to mxd
arcpy.mapping.AddLayer(df, nl)

##zooms to layer
df.zoomToSelectedFeatures()

extent=df.extent




for nl in arcpy.mapping.ListLayers(mxd, "", df):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.RemoveLayer(df, nl)

arcpy.RefreshActiveView() 

#mapDocument
mxd = arcpy.mapping.MapDocument(r"***************************.mxd")


nl2= arcpy.mapping.Layer(r"**********************************")

##setting dataset variable
df = arcpy.mapping.ListDataFrames(mxd)[0]

df.extent=extent

##adds layer variable to mxd
arcpy.mapping.AddLayer(df, nl2)


##exports current map extent to png
arcpy.mapping.ExportToPNG(mxd,r"************************",df,df_export_width=550,df_export_height=480)

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 19:15:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/cant-get-selected-feature-to-clear/m-p/427738#M14384</guid>
      <dc:creator>ja3</dc:creator>
      <dc:date>2021-12-11T19:15:20Z</dc:date>
    </item>
    <item>
      <title>Re: Cant get selected feature to clear?</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/cant-get-selected-feature-to-clear/m-p/427739#M14385</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Oh, by the way, there is a bug in setting dataframe extents.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;You sometimes have to do it twice, so it is a good practice to do it twice in your code.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Jul 2013 18:41:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/cant-get-selected-feature-to-clear/m-p/427739#M14385</guid>
      <dc:creator>markdenil</dc:creator>
      <dc:date>2013-07-11T18:41:59Z</dc:date>
    </item>
  </channel>
</rss>

