FeatureClassToShapefile_conversion fails when input is featurelayer

1489
5
04-23-2021 02:44 AM
leonoestergaard
Occasional Contributor

Im trying to create a shapefile with input from a featurelayer

 

it fails with:

WARNING: Failed to convert: MyLayer. ERROR 000210: Cannot create output c:\temp\Shapes\MyLayer.shp
Failed to execute (CopyFeatures).

 

 

fc = r"c:\connections\MyEditor@MyDb.sde\mydb.measurement.Line"
arcpy.MakeFeatureLayer_management(fc,"MyLayer")
print(arcpy.GetCount_management("MyLayer"))
arcpy.FeatureClassToShapefile_conversion("MyLayer", "c:\\temp\\Shapes") #<-- This fails

#If I in the FeatureClassToShapefile_conversion uses the featureclass instead of the featurlayer it works.

arcpy.FeatureClassToShapefile_conversion(fc, "c:\\temp\\Shapes") #<-- This works

 

 

What can I be doing wrong? The count returns 420504 so the featuerlayer contains data

0 Kudos
5 Replies
DanPatterson
MVP Esteemed Contributor

I suspect it can't find "MyLayer" since it doesn't know where it is, I don't think you "fc" plus "MyLayer" makes an actual layer file.  It needs a workspace, then the layer name

Make Feature Layer (Data Management)—ArcGIS Pro | Documentation

 

It would probably work if you created a *.lyrx file (a layer file) with a path.


... sort of retired...
0 Kudos
leonoestergaard
Occasional Contributor

Well, just tried to run the same code in python3 and it works...

0 Kudos
DanPatterson
MVP Esteemed Contributor

Layer properties—ArcGIS Pro | Documentation would be a good check prior to using a feature layer.

python3? all pro tools have to use python 3


... sort of retired...
leonoestergaard
Occasional Contributor

It works on python27 with arcgis 10.6

0 Kudos
MarkKinnaman
Occasional Contributor

I believe you need to use Copy management to create a shapefile or feature class.

Make Feature Layer (Data Management)

The temporary feature layer can be saved as a layer file using the Save To Layer File tool or can be saved as a new feature class using the Copy Features tool.

 

0 Kudos