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.
arcpy.env.workspace = r"C:\FULLPATH\TEST.gdb"
sheets = "Sheets"
parcels = "Parcels"
sheet_lyr = arcpy.management.SelectLayerByLocation(sheets, "INTERSECT", parcels)
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?