Flash Selected Feature?

1645
3
06-09-2014 12:50 PM
JohnDye
Occasional Contributor III
Anyone know how to Flash a Selected Feature using Python or to call the ArcObjects function through Python?

I have a process set up to allow the user to easily Query a Layer and then Zoom to the Selected Feature, immediately after zooming to the feature though, I want the feature to Flash the same as it would through the Identify Window in order to draw the user's attention to it.

I tried creating a crude version of it using SelectLayerByAttribute, but it's god-awful slow.
def crudeFlash(FeatureLayer, Query):
     mxd = arcpy.mapping.MapDocument("Current")
     df = arcpy.mapping.ListDataFrames(mxd)[0]
     arcpy.SelectLayerByAttribute_management(FeatureLayer, "NEW_SELECTION", Query)
     df.zoomToSelectedFeatures()
     arcpy.SelectLayerByAttribute_management(FeatureLayer, "CLEAR_SELECTION")
     arcpy.SelectLayerByAttribute_management(FeatureLayer, "NEW_SELECTION", Query)
     arcpy.SelectLayerByAttribute_management(FeatureLayer, "CLEAR_SELECTION")
     
>>> crudeFlash("MyLayer", '"NAME" = ' + "'MyFeature'")


The reason I don't want to just leave the feature selected is that I don't want to create a situation where the User might then run some sort of GeoProcess and it only executes against the single selected feature.
Tags (2)
3 Replies
MattEiben
Occasional Contributor
You could try using the geometry and a search cursor instead.  It should be much faster and not involve selecting any features.

zoomToGeom = [row[0] for row in arcpy.da.SearchCursor(FeatureLayer,["SHAPE@"],query)][0]
df.extent = zoomToGeom


You may have to run an arcpy.RefreshActiveView() afterwards if your view doesn't automatically refresh.

If it zooms in too much, you can adjust it with something like this:
df.scale *= 1.25
JohnDye
Occasional Contributor III
Thanks Matt,
That was a nice little improvement over df.zoomToSelectedFeatures() but I'm looking for a method to actually flash the selected feature as you can in ArcMap through the identify window.

It generates a little crosshair on the screen and then flashes the feature in a kind of dark-green color.
0 Kudos
MattEiben
Occasional Contributor
As Sol was referencing, there seems to be a way to do this through the ArcObjects SDK as referenced at the bottom of this thread (Using C#):
http://forums.arcgis.com/threads/23523-Programatically-PanTo-ZoomTo-and-then-Flash-features

I haven't been able to find an equivalent in ArcPy yet though.