Select to view content in your preferred language

How to make a selection in a map (mxd) from a stand-alone python script?

326
1
02-01-2012 03:14 AM
Ulises
by
Occasional Contributor III
I have a map document created in ArcGIS 10 that is access daily by our users.  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?  We want to run the script every night.

Thanks
Ulises Feliciano Troche
Tags (2)
0 Kudos
1 Reply
JeffBarrette
Esri Regular Contributor
Yes.  Have you tried something like:

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")



Jeff
0 Kudos