arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>addOutputsToMap<SPAN class="operator token">=</SPAN><SPAN class="token boolean">False</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>MakeTableView_management<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"<workspace>\\RDA.DBO.Immediate_Assessment"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"tmp_tbl"</SPAN><SPAN class="punctuation token">,</SPAN>where_clause<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># <Result 'tmp_tbl'></SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>GetCount_management<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'tmp_tbl'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># File "<string>", line 1, in <module></SPAN>
<SPAN class="comment token"># File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\management.py", line 17492, in GetCount</SPAN>
<SPAN class="comment token"># raise e</SPAN>
<SPAN class="comment token"># File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\management.py", line 17489, in GetCount</SPAN>
<SPAN class="comment token"># retval = convertArcObjectToPythonObject(gp.GetCount_management(*gp_fixargs((in_rows,), True)))</SPAN>
<SPAN class="comment token"># File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\geoprocessing\_base.py", line 496, in <lambda></SPAN>
<SPAN class="comment token"># return lambda *args: val(*gp_fixargs(args, True))</SPAN>
<SPAN class="comment token"># Error in sys.excepthook:</SPAN>
<SPAN class="comment token"># Traceback (most recent call last):</SPAN>
<SPAN class="comment token"># File "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\Extensions\Microsoft\Python\Core\ptvsd\debugger.py", line 2409, in _excepthook</SPAN>
<SPAN class="comment token"># print_exception(exc_type, exc_value, exc_tb)</SPAN>
<SPAN class="comment token"># File "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\Extensions\Microsoft\Python\Core\ptvsd\debugger.py", line 2656, in print_exception</SPAN>
<SPAN class="comment token"># sys.stdout.write(out)</SPAN>
<SPAN class="comment token"># AttributeError: 'NoneType' object has no attribute 'write'</SPAN>
<SPAN class="comment token"># </SPAN>
<SPAN class="comment token"># Original exception was:</SPAN>
<SPAN class="comment token"># Traceback (most recent call last):</SPAN>
<SPAN class="comment token"># File "<string>", line 1, in <module></SPAN>
<SPAN class="comment token"># File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\management.py", line 17492, in GetCount</SPAN>
<SPAN class="comment token"># raise e</SPAN>
<SPAN class="comment token"># File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\management.py", line 17489, in GetCount</SPAN>
<SPAN class="comment token"># retval = convertArcObjectToPythonObject(gp.GetCount_management(*gp_fixargs((in_rows,), True)))</SPAN>
<SPAN class="comment token"># File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\geoprocessing\_base.py", line 496, in <lambda></SPAN>
<SPAN class="comment token"># return lambda *args: val(*gp_fixargs(args, True))</SPAN>
<SPAN class="comment token"># arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.</SPAN>
<SPAN class="comment token"># ERROR 000732: Input Rows: Dataset tmp_tbl does not exist or is not supported</SPAN>
<SPAN class="comment token"># Failed to execute (GetCount).</SPAN>
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
If the arcpy.env.addOutputsToMap is set to True, the same code will work.
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>addOutputsToMap<SPAN class="operator token">=</SPAN><SPAN class="token boolean">True</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>MakeTableView_management<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"<workspace>\\RDA.DBO.Immediate_Assessment"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"tmp_tbl"</SPAN><SPAN class="punctuation token">,</SPAN>where_clause<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>GetCount_management<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'tmp_tbl'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># <Result '45'></SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
What I really want to do is the same as the Python following example, but I don't want to add the temporary layer to the map (the code should not rely on an active map in my case)
<SPAN class="comment token"># Name: DeleteFeatures_Example2.py</SPAN>
<SPAN class="comment token"># Description: Delete features from a feature class based on an expression</SPAN>
<SPAN class="comment token"># Import system modules</SPAN>
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="comment token"># Set environment settings</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> <SPAN class="string token">"C:/data/airport.gdb"</SPAN>
<SPAN class="comment token"># Set local variables</SPAN>
inFeatures <SPAN class="operator token">=</SPAN> <SPAN class="string token">"parcels"</SPAN>
outFeatures <SPAN class="operator token">=</SPAN> <SPAN class="string token">"C:/output/output.gdb/new_parcels"</SPAN>
tempLayer <SPAN class="operator token">=</SPAN> <SPAN class="string token">"parcelsLayer"</SPAN>
expression <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>AddFieldDelimiters<SPAN class="punctuation token">(</SPAN>tempLayer<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"PARCEL_ID"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">" = 'Cemetery'"</SPAN>
<SPAN class="comment token"># Execute CopyFeatures to make a new copy of the feature class</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>CopyFeatures_management<SPAN class="punctuation token">(</SPAN>inFeatures<SPAN class="punctuation token">,</SPAN> outFeatures<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Execute MakeFeatureLayer</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>MakeFeatureLayer_management<SPAN class="punctuation token">(</SPAN>outFeatures<SPAN class="punctuation token">,</SPAN> tempLayer<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Execute SelectLayerByAttribute to determine which features to delete</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>SelectLayerByAttribute_management<SPAN class="punctuation token">(</SPAN>tempLayer<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"NEW_SELECTION"</SPAN><SPAN class="punctuation token">,</SPAN>
expression<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Execute GetCount and if some features have been selected, then </SPAN>
<SPAN class="comment token"># execute DeleteFeatures to remove the selected features.</SPAN>
<SPAN class="keyword token">if</SPAN> int<SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>GetCount_management<SPAN class="punctuation token">(</SPAN>tempLayer<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">></SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">:</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>DeleteFeatures_management<SPAN class="punctuation token">(</SPAN>tempLayer<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
the above code is from ESRI help document:
Delete Features—Data Management toolbox | ArcGIS Desktop
So the question is:
Can we make in-memory feature layers or tables without adding them to a map?