<?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 Re: How to make a selection in a map (mxd) from a stand-alone python script? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-make-a-selection-in-a-map-mxd-from-a-stand/m-p/163431#M12506</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Yes.&amp;nbsp; Have you tried something like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy
mxd = arcpy.mapping.MapDocument("path to mxd")
lyr = arcpy.mapping.ListLayers(mxd, "layer name")[0]
arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", "some query")
mxd.save()

#If you don't want to save the selection to the existing MXD, try saving it to another file:
mxd.saveACopy("path to new MXD")

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jeff&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 08:33:44 GMT</pubDate>
    <dc:creator>JeffBarrette</dc:creator>
    <dc:date>2021-12-11T08:33:44Z</dc:date>
    <item>
      <title>How to make a selection in a map (mxd) from a stand-alone python script?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-make-a-selection-in-a-map-mxd-from-a-stand/m-p/163430#M12505</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a map document created in ArcGIS 10 that is access daily by our users.&amp;nbsp; Is there any way to run a selection (by location or attribute) from a stand alone script and save the mxd so users see the updated selection when they open the map document?&amp;nbsp; We want to run the script every night.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 01 Feb 2012 11:14:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-make-a-selection-in-a-map-mxd-from-a-stand/m-p/163430#M12505</guid>
      <dc:creator>Ulises</dc:creator>
      <dc:date>2012-02-01T11:14:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a selection in a map (mxd) from a stand-alone python script?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-make-a-selection-in-a-map-mxd-from-a-stand/m-p/163431#M12506</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Yes.&amp;nbsp; Have you tried something like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy
mxd = arcpy.mapping.MapDocument("path to mxd")
lyr = arcpy.mapping.ListLayers(mxd, "layer name")[0]
arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", "some query")
mxd.save()

#If you don't want to save the selection to the existing MXD, try saving it to another file:
mxd.saveACopy("path to new MXD")

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jeff&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:33:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-make-a-selection-in-a-map-mxd-from-a-stand/m-p/163431#M12506</guid>
      <dc:creator>JeffBarrette</dc:creator>
      <dc:date>2021-12-11T08:33:44Z</dc:date>
    </item>
  </channel>
</rss>

