By Bella Beharrell

2019-01-10 17:38:26 8 Comments

I have created a simple model to transfer multiple feature classes to a shapefile. With the model I exported a .py script which I'd like to run with my task manager to update any changes each day. The script that runs with out overwriting:

# Import arcpy module
import arcpy

# Local variables:
adverse = "F:\\Atco_gis\\temp_shapefiles\\LP_Layers_Temp.gdb\\adverse"
comments = "F:\\Atco_gis\\temp_shapefiles\\LP_Layers_Temp.gdb\\comments"
desig_crossing = "F:\\Atco_gis\\temp_shapefiles\\LP_Layers_Temp.gdb\\desig_crossing"
Temp_LP_Layers = "F:\\Atco_gis\\temp_shapefiles\\Temp_LP_Layers"
Temp_LP_Layers__2_ = Temp_LP_Layers

# Process: Feature Class To Shapefile (multiple)
arcpy.FeatureClassToShapefile_conversion("F:\\Atco_gis\\temp_shapefiles\\LP_Layers_Temp.gdb\\adverse;F:\\Atco_gis\\temp_shapefiles\\LP_Layers_Temp.gdb\\comments;F:\\Atco_gis\\temp_shapefiles\\LP_Layers_Temp.gdb\\desig_crossing", Temp_LP_Layers)

I have been reading that:

arcpy.env.overwriteOutput = True

should solve the problem however it leaves me with a new output with _1 or _2 depending how many times the script has been ran.

Any suggestions?


@PolyGeo 2019-01-15 22:47:35

The Feature Class To Shapefile tool is a Python Script Tool and you can see its source by locating it in the Search Window and right-clicking it to choose Edit from its context menu.

It is this code, in particular a function named ConversionUtils.GenerateOutputName that appears to be generating the names with _1, _2, etc (depending how many times the script has been run) appended to them.

This behaviour is mentioned in the Feature Class To Shapefile Help and that is what bypasses your setting for arcpy.env.overwriteOutput:

If the output shapefile already exists in the Output Folder, a number will be appended to the end to make the shapefile name unique (for example, rivers_1.shp).

I would not recommend trying to change the source for this tool, and I think you will find it very difficult to try and copy the source and edit it to create a new tool.

Instead I recommend doing as @Aaron suggested in a comment and write some code, to insert before you run arcpy.FeatureClassToShapefile_conversion(), which deletes existing copies of any shapefiles before recreate them.

That code would involve using the arcpy.Exists() and arcpy.Delete_management() functions, along with some string manipulation of the pathnames to your output shapefiles.

Related Questions

Sponsored Content

3 Answered Questions

[SOLVED] Installing third party python libraries in ArcGIS location

0 Answered Questions

Pyscripter crashes with EOFError timed out

2 Answered Questions

1 Answered Questions

1 Answered Questions

[SOLVED] Using ArcGIS Data Interoperability tool in ArcPy?

1 Answered Questions

3 Answered Questions

0 Answered Questions

Using an ArcSDE Connection through Python

Sponsored Content