I have a script that worked fine a month ago but I suspect due to some reconfiguring of my citrix profile by IT as part of a maintennance drill they changed something that affects my ability to create folders and file gdbs from a script. In this script, a for loop is used to create multiple clips of a three large line feature classes into smaller areas. I want the script to create a folder for each location and a generic Features.gdb within that folder and I thought this happens as part of the clip tool being called in the script.

Here is my code:

outputFolder = r"N:\Common\MapClips\CO_181"
env.workspace = r"N:\Workspace\Updates_2017\gisdb\HERE_2017_Q1_3530_Recology2017Q1.gdb"
env.overwriteOutput = True

Cutter = r"N:\Common\MapClips\CO_181\Features.gdb\CO_181_Dissolve"
Dough1 = r"N:\Workspace\Updates_2017\gisdb\HERE_2017_Q1_3530_Rec2017Q1.gdb\here_2017_q1_streets"
Dough2 = r"N:\Workspace\Updates_2017\gisdb\HERE_2017_Q1_3530_Rec2017Q1.gdb\here_2017_q1_streets_alias"
Dough3 = r"N:\Workspace\Updates_2017\gisdb\HERE_2017_Q1_3530_Rec2017Q1.gdb\here_2017_q1_streets_parity"

fcs = [Dough1, Dough2, Dough3]

with da.SearchCursor(Cutter, ["SHAPE@", "Fran"]) as rows:
    for row in rows:
        #1. create fgdb in outputFolder variable
        outGDB = os.path.join(outputFolder,"CO_" + row[1], "Features.gdb")
        geom = row[0]# arcpy.CopyFeatures_management(geom, r"in_memeory\temp")
        for fc in fcs:
            out_feature_class = os.path.join(outputFolder, outGDB, row[1]+ "_" + os.path.basename(fc))
            print out_feature_class
            del fc
        del row
        print "Created " + out_feature_class

This throws the following error:

 Traceback (most recent call last):
      File "C:\Python27\ArcGIS10.2\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 323, in RunScript
        debugger.run(codeObject, __main__.__dict__, start_stepping=0)
      File "C:\Python27\ArcGIS10.2\Lib\site-packages\pythonwin\pywin\debugger\__init__.py", line 60, in run
        _GetCurrentDebugger().run(cmd, globals,locals, start_stepping)
      File "C:\Python27\ArcGIS10.2\Lib\site-packages\pythonwin\pywin\debugger\debugger.py", line 654, in run
        exec cmd in globals, locals
      File "N:\Python\Completed scripts\Ratto_Cal_Street_Update_Prep.py", line 3, in <module>
        import arcpy
      File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\analysis.py", line 56, in Clip
        raise e
    ExecuteError: ERROR 000210: Cannot create output N:\Common\MapClips\CO_181\CO_Nov\Features.gdb\Nov_here_2017_q1_streets
    Failed to execute (Clip).

I went and created the first output location manually:


And it worked in the first iteration and then bombed when it got to the next clip feature as there was not yet a folder or gdb created for it yet.

I know this worked fine for me before and I didn't have to manually create the folders and fgdbs. I can do that if necessary but I would prefer to have this process done automatically through the script.

  • 2
    You're not creating the GDB. Add if not arcpy.Exists(os.path.join(outputFolder, outGDB)): arcpy.CreateFileGDB_management(outputFolder,outGDB) into your loop and it should work.. as you said you could manually create a GDB in the folder then arcpy should have no reason not to do the same. You're using an arcpy.da cursor (I think that's what da. is), so you don't need to del row as the with handles all of that. Why del fc? I can't see any reason for it. – Michael Stimson Oct 5 '17 at 0:02
  • @MichaelStimson OK. I thought it worked fine before but maybe the output locations were already there. Put in your bit of code and am now getting a generic ExecuteError: ERROR 999999: Error executing function. Failed to execute (CreateFileGDB). – geoJshaun Oct 5 '17 at 0:11
  • 1
    Is the path and name of the GDB valid? What happens if you execute via the python window of ArcCatalog? – Michael Stimson Oct 5 '17 at 0:17
  • @MichaelStimson should be. Used the same path structure when I did it manually – geoJshaun Oct 5 '17 at 0:20
  • 1
    Do you get the same error when you execute the command in the python window of ArcCatalog? Try copy/pasting both paths, the existing and intended, into notepad on two lines and check carefully one line to the other for any mistakes; while you're doing that make sure the path doesn't contain bad characters. – Michael Stimson Oct 5 '17 at 0:25

If you are seeing an error of:

ERROR 000210: Cannot create output N:\Common\MapClips\CO_181\CO_Nov\Features.gdb\Nov_here_2017_q1_streets

I think you should try and run the test script below to see if the problem can be reproduced outside of your application:

import arcpy
arcpy.CreateFeatureclass_management(r"N:\Common\MapClips\CO_181\CO_Nov\Features.gdb", "Nov_here_2017_q1_streets")

If that does not error then try putting a print statement into your code to double-check that your out_feature_class variable is set to what you think it is:

  • 1
    followed your steps and everything is fine until I try to create a gdb through the script. Paths are correct. I thinl I'll have to take the rest up with my IT team. Thanks! – geoJshaun Oct 5 '17 at 22:44

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.