I would like the following to select (highlight) the "project" layer that intersects the grid, and then pull a record from the selected "Grid". I do not need to save the layer.

Note: Running the script from within ArcMap in the Python Console window.

import arcpy

# Make a layer from the feature class

# Then add a selection to the layer based on location to features in another feature class 

This code runs and no errors are given, yet it does not select(highlight) any features. Any Idea why? Also runs really slow.


Basically I'm trying to do this:

enter image description here

This runs really fast almost instant, but I want to do the same using python. I just need a value from the selected feature's table, I don't need a copy of the layer.

Part of the solution may be to use the in-memory workspace which is

Writing data to the in-memory workspace is often significantly faster than writing to other formats...

Just not sure how to implement in-memory workspace

  • Are you running this script from within ArcMap (i.e. in the Python console)? Or from outside ArcMap (i.e. within IDLE or another Python editor)? The only way ArcMap will "select(highlight) any features" is from within ArcMap. I suspect that you are running the script from outside ArcMap, because the import arcpy command takes awhile to run.
    – dmahr
    Commented Jul 4, 2012 at 16:05
  • I'm running the script from within ArcMap in the Python Console window. Commented Jul 4, 2012 at 16:07
  • If you're running it from within ArcMap, you do not need the arcpy.MakeFeatureLayer() line, since project is already a layer. Just do arcpy.SelectLayerByLocation_management("project","INTERSECT","Grid").
    – dmahr
    Commented Jul 4, 2012 at 16:48
  • great question format!
    – Brad Nesom
    Commented Jul 4, 2012 at 17:06
  • Thanks @dmahr, still runs slower than the built-in Select by Attribute but works. Commented Jul 4, 2012 at 17:35

1 Answer 1


Good question!

Dmahr is right, it's quicker to simply just select the layer instead of creating a feature layer. I would also add the rest of the variables, even though they are optional.

arcpy.SelectLayerByLocation_management ("project_lyr", "INTERSECT", "Grid", "#", "NEW_SELECTION")

Another thing I find, is that running things in the python window of ArcMap is always slower. I find that if you write the code to a .py file, add it as a script to the toolbox and then run it, the processing will go faster.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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