1

I have a database of orders, with geo data attached.

I want the subset of features related to a specific order to be highlighted on screen (for starters in ArcMap, but later in Flex)

in a python geoprocessing script I use SelectLayerByAttribute, and this seems to work. (I printed the GetCount and got 11 reported).

However, I do not see the selection being hilighted in the map. (since I have to search multiple layers later, a script seems unavoidable)

should a selection made in this way be automatically visible in arcMap (and selected in table view) ? If not, how do I achieve this effect, i.e. that a selection made in the geoprocessing script is visible by the user firing off the script ?

code :

# -*- coding: utf-8 -*-
# Import arcpy module
import arcpy

#input parameters
Order_To_Find   = arcpy.GetParameterAsText(0)

try:
    mxd = arcpy.mapping.MapDocument(r"E:\GIS\GIS_projecten\034_Werkorders\04_Map\orders.mxd")
    whereclause = " \"ORDERNUMMER\" LIKE \'%CEM MIGRATIE_ 17%\' "
    for lyr in arcpy.mapping.ListLayers(mxd):
        print lyr.name
        if lyr.name == "MUT_E_ASSET_GEO_ACT_P":
            arcpy.SelectLayerByAttribute_management(lyr,"NEW_SELECTION",whereclause)
except:
    print arcpy.GetMessages()
  • It doesn't work for me either. I tried .RefreshActiveView() and still no highlights – Paul Kranz Jul 31 '17 at 19:15
1

I think you need to set the mxd object to the current open mxd like this:

mxd = arcpy.mapping.MapDocument('current')

Otherwise, it is opening a second map behind the scenes when you have a path hard coded in like you do in your script. By using the current mxd, you should see any selections that occur on the layers in the TOC.

  • Many thanks for your suggestion. I did get this working, but unfortunately I cannot use this in a flex viewer, because "CURRENT" only works in ArcMAP. We are back to creating result sets in a database, then publishing this data(set) in a separate layer. any smarter approaches than that are much appreciated. – GeoNoob Nov 11 '14 at 14:57
0

You already have your where clause, so if you make a copy of your layer in your MXD (either using ArcMap or programmatically), and style it differently, then you can apply that same where clause as a Definition Query to the copy of the layer.

That way only the "selected" features will be displayed in the copy of the layer.

  • thanks for your suggestion. I will try this. you propose to have the python code to modify just the definition query in the second layer, I understand. – GeoNoob Nov 14 '14 at 13:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.