I am attempting to build an ArcGIS Python script within a basic Toolbox so I can scan through and clip all shapefiles within predefined folders.

This is easy with the Geoprocessing tool "Clip" for single features or multiple with using batch. However, I have reached a very frustrating impasse and haven't been able to find a solution. I wrote a basic code below to show the problem I am having... what am I doing wrong?

import arcpy, os
arcpy.AddMessage("Basic Clip Attempt")
Clip_Feautre = arcpy.GetParameterAsText(0)
# "X:/3 GIS/1_Projects/2017_Bacardi_Creek/06_Geodatabase/2017_Bacardi_Creek.gdb/Boundaries/Boundary_Extended"
Target_Feature = arcpy.GetParameterAsText(1)
# "X:/3-GIS/5_BaseData/AltaLIS/AltaLIS_Hydrography_160619/BF_HYDRO_POLYGON.shp"
Save_Location = arcpy.GetParameterAsText(2)
# "X:/3-GIS/1_Projects/2017_Bacardi_Creek/06_Geodatabase/2017_Bacardi_Creek.gdb/Scratch/Hydro_Scratch"

if os.path.exists((Target_Feature)):
    arcpy.AddMessage(Target_Feature + "----- Path Exists")
    arcpy.AddMessage(Target_Feature + "----- Path Does Not Exist")

# Guess what... the file exists!
# X:\3-GIS\5_BaseData\AltaLIS\AltaLIS_Hydrography_160619\BF_HYDRO_POLYGON.shp----- Path Exists
# The following is a copy from an ArcGIS geoprocessing run that worked.
arcpy.Clip_analysis(in_features="X:/3-GIS/5_BaseData/AltaLIS/AltaLIS_Hydrography_160619/BF_HYDRO_POLYGON.shp", clip_features="X:/3-GIS/1_Projects/2017_Bacardi_Creek/06_Geodatabase/2017_Bacardi_Creek.gdb/Boundaries/Boundary_Extended", out_feature_class="X:/3-GIS/1_Projects/2017_Bacardi_Creek/06_Geodatabase/2017_Bacardi_Creek.gdb/Scratch/Hydro_Scratch", cluster_tolerance="")
# ERROR 000229: Cannot open X:/3-GIS/5_BaseData/AltaLIS/AltaLIS_Hydrography_160619/BF_HYDRO_POLYGON.shp
# Failed to execute (Clip).

arcpy.AddMessage("Attempt 1 has failed.  Attempt 2 in progress")

in_features_raw = r'X:/3-GIS/5_BaseData/AltaLIS/AltaLIS_Hydrography_160619/BF_HYDRO_POLYGON.shp'
clip_features_raw = r'X:/3-GIS/1_Projects/2017_Bacardi_Creek/06_Geodatabase/2017_Bacardi_Creek.gdb/Boundaries/Boundary_Extended'
out_feature_class_raw = r'X:/3-GIS/1_Projects/2017_Bacardi_Creek/06_Geodatabase/2017_Bacardi_Creek.gdb/Scratch/Hydro_Scratch'
    # ERROR 000732: Input Features: Dataset X:/3-GIS/5_BaseData/AltaLIS/AltaLIS_Hydrography_160619/BF_HYDRO_POLYGON.shp does not exist or is not supported
    # Failed to execute (Clip).
    arcpy.AddMessage("Attempt 2 has failed... Attempt 3 in progress...")
        # ERROR 000229: Cannot open X:\3-GIS\5_BaseData\AltaLIS\AltaLIS_Hydrography_160619\BF_HYDRO_POLYGON.shp
        # Failed to execute (Clip).
        arcpy.AddMessage("Attempt 3 has failed... Attempt 4 in progress........")
            Clip_Feautre_replace = Clip_Feautre.replace("\\","\\\\")
            Target_Feature_replace = Target_Feature.replace("\\","\\\\")
            Save_Location_replace = Save_Location.replace("\\","\\\\")
            # ERROR 000229: Cannot open X:\\3-GIS\\5_BaseData\\AltaLIS\\AltaLIS_Hydrography_160619\\BF_HYDRO_POLYGON.shp
            # Failed to execute (Clip).
            arcpy.AddMessage("Attempt 4 has failed... .... I don't know...")
  • What line does the error occur on? Can you give the exact error message.. it contains much more information than just a (mostly) useless error number. Is it possible your output feature class exists and is locked by ArcCatalog, python or ArcMap? What is the setting of arcpy.env.overwriteOutput? – Michael Stimson Apr 26 '17 at 22:14
  • 2
    Can we just focus on 1 attempt instead of 4 separate ones? Run in arcmap > Results > Copy as Python snippet. See how that compares with yours. – Paul Apr 26 '17 at 22:20
  • 1
    I have noticed that your paths are inconsistent, some start with X:/3 GIS/ and some start with X:/3-GIS/... dashes in paths are bad for shapefiles and can cause unexpected behavior, can you try to execute your script from a different location (try SUBST technet.microsoft.com/en-us/library/bb491006.aspx for example SUBST B: "X:/3-GIS/5_BaseData/AltaLIS/AltaLIS_Hydrography_160619") then execute with paths from B drive. – Michael Stimson Apr 26 '17 at 22:29
  • The code with "\\" works outside of the the ArcGIS tool environment with no problems even if the output features exist (just copy over them as arcpy.env.overwriteOutput = True). "Copy as Python snippet" was my very first attempt, result is already above and fails to work through as an ArcGIS tool. The folder naming is a mess (created before I got here), but it has not caused problems in geoprocessing for me (yet)... just the python coding in ArcGIS tool environment is failing to execute. – DrChris Apr 27 '17 at 22:51

According to ESRI, the 000229 ERROR might mean the function cannot work out where your data lives on your machine. The clip function works within your ArcMap session because it has access to the data already in memory. It does not work within your script because arcpy has decided that is an invalid directory and freaks out. Here is some info on the error. With arcpy, avoid using hyphens and beginning directories with numbers.

  • I have had issues with this sort of thing before... as well as very long path names. If you can't change the folder names, for example if you're using someone elses' data from another company or department, try the subst trick, it works well for me. Since floppy drives have gone the way of the dinosaur A and B are usually free for the taking. – Michael Stimson Apr 26 '17 at 23:04
  • The python code works outside of ArcGIS. I am able to auto clip through any number of desired shapefiles... but every time I attempt to use the tool through ArcGIS... same error... driving me up the wall now. – DrChris Apr 27 '17 at 22:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.