AnsweredAssumed Answered

How to SelectByLocation, in memory, without adding to current map?

Question asked by VCEGIS500 on Jul 7, 2020
Latest reply on Jul 8, 2020 by VCEGIS500

I am attempting to perform a SelectByLocation on a feature class and export that selection. I am running this code directly in the Python Window in ArcGIS Pro. Eventually this operation will be ported over to a larger script that will become a tool in a toolbox. If I use EnvManager as shown below to set "addOutputsToMap=True", the below works fine. When set to False, it does not.

import arcpy

arcpy.env.workspace = r"C:\FULLPATH\TEST.gdb"

sheets = "Sheets"
parcels = "Parcels"

with arcpy.EnvManager(addOutputsToMap=True):
    sheet_lyr = arcpy.management.SelectLayerByLocation(sheets, "INTERSECT", parcels)
arcpy.management.CopyFeatures(sheet_lyr, "Sheet_Intersect")

I have tried all sorts of combinations using MakeFeatureLayer(), using r"memory\XXX" as a workspace, using getOutput() from the Result, etc., and cannot figure out any combination that avoids adding the unnecessary intermediate layer "sheet_lyr" to the map. There seems to be several different methods that all work when adding the "sheet_lyr" to the map, but none when "addOutputsToMap=False".

 

Is there no way to perform a SelectByLocation and export the result entirely within memory workspace, without adding a layers to a map? Or is it just not possible to do directly in the Python Window?

Outcomes