AnsweredAssumed Answered

Trouble creating `Layer` objects in ArcGIS Pro 2.2.4

Question asked by aorr_Geosyntec on Nov 7, 2018
Latest reply on Nov 15, 2018 by aorr_Geosyntec

Hi All, I'm having much difficulty with the Make Feature Layer examples from the docs here

 

I'm running arcpy from a standalone script using the "c:\Program Files\ArcGIS\Pro\bin\Python\scripts\proenv.bat" provided by ESRI. 

 

In their example, it is possible to set the workspace, and then pass a shapefile inside that workspace to the `MakeFeatureLayer_management` function. When I try this in a minimal script I get an unhelpful error message.

 

<test.py>

import arcpy
print(arcpy.GetInstallInfo())
ws = 'C:\\Users\\myself\\testing\\test_query_bboxes'
fc = 'test_bboxes.shp'

arcpy.env.workspace = ws
arcpy.MakeFeatureLayer_management(fc, 'test_lyr')

<output>
{'InstallDir': 'c:\\program files\\arcgis\\pro\\',  
'Installer': 'myself', 
'ProductName': 'ArcGISPro', 
'Version': '2.2.4', 
'SourceDir': 'C:\\Users\\myself\\Documents\\ArcGIS Pro 2.2\\ArcGISPro\\', 
'InstallType': 'N/A', 
'BuildNumber': '12813', 
'InstallDate': '11/7/2018', 
'InstallTime': '12:51:07', 
'SPNumber': 'N/A', 
'SPBuild': 'N/A'}

RuntimeError Traceback (most recent call last)
<ipython-input-1-f8756495bde9> in <module>()
5
6 arcpy.env.workspace = gdb
----> 7 arcpy.MakeFeatureLayer_management(fc, 'test_lyr')

C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py in MakeFeatureLayer(in_features, out_layer, where_clause, workspace, field_info)
6532 return retval
6533 except Exception as e:
-> 6534 raise e
6535
6536 @gptooldoc('MakeImageServerLayer_management', None)

C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py in MakeFeatureLayer(in_features, out_layer, where_clause, workspace, field_info)
6529 from arcpy.arcobjects.arcobjectconversion import convertArcObjectToPythonObject
6530 try:
-> 6531 retval = convertArcObjectToPythonObject(gp.MakeFeatureLayer_management(*gp_fixargs((in_features, out_layer, where_clause, workspace, field_info), True)))
6532 return retval
6533 except Exception as e:

C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py in <lambda>(*args)
494 val = getattr(self._gp, attr)
495 if callable(val):
--> 496 return lambda *args: val(*gp_fixargs(args, True))
497 else:
498 return convertArcObjectToPythonObject(val)

RuntimeError: Object: Error in executing tool

```

 

This works great with the `arcpy` from ArcMap 10.6 for both compete paths to the input featureclass (both in geodatabases an as shapefiles) and as names within the workspace. What am in missing about how i'm supposed to initialize a `Layer` object in `arcpy` from ArcGIS Pro?

Outcomes