I'm trying to populate a Geodatabase with roundabout 60 Datasets with a new Featureclass for each Dataset. To do this, i wrote a python-standalone-script that loops through these datasets and creates a new Featureclass with the "CreateFeatureclass_management"-Tool and do some stuff with this Featureclass afterwards.

This works for the first Dataset, but when my script reaches this command for the next Dataset, the processing of my script is interrupted. I don't get a Traceback, instead an Windows-Error-message pops up, saying smth. like "pythonw.exe registered an error and has to be cancelled" (Maybe the wording is a bit different, since i translated it from german).

So, this Problem always occures for the second Featureclass that should be generated. If i extract the first Dataset with the correct generated Featureclass from my Geodatabase and start the script again, again the Featureclass will be added to the first Dataset (the former second), but not to the following. So it's not a question of my Data. I also doubt if it's something in my scriptcode itself, since i wrote a very simple Testscript afterwards, that is able to create 4 Featureclasses in ONE Dataset, but isn't able to create Featureclasses in more than one Dataset.

I really dont see any reason for my script to not create these Featureclasses. If you demand it, i can definitely post some scriptcode. Anyway, i fear that it has smth to do with my cache or so.

Here is the code of my testsript: ( It actually breaks at the first AddField_management instead of my CreateFeatureclass_management, after I changed it a bit)

import arcpy, os

Geodatabase = r"D:\GIS\STK\124_NDS\STK_124_NDS.gdb"
arcpy.env.overwriteOutput = True

def CreateFeatureclasses(workspace):
    arcpy.env.workspace = Geodatabase
    listDatasets = arcpy.ListDatasets("", "Feature")
    for dataset in listDatasets:
        datasetPath = workspace + os.sep + dataset
        arcpy.env.workspace = datasetPath

        print "Dataset: " + dataset
        out_name = "BF_Stao_Bodenprofil_P_" + dataset[9:]
        Bohrpunkt_fc = arcpy.CreateFeatureclass_management (datasetPath, out_name, "POINT")
        fcList = arcpy.ListFeatureClasses()
        for fc in fcList:
            if fc[:10] == "Bohrpunkte":
                Punkteliste = []
                zeilen = arcpy.SearchCursor(fc)
                for zeile in zeilen:
                    Bohrkreisgeometrie = zeile.getValue("Shape")
                    Bohrpunkt = Bohrkreisgeometrie.trueCentroid
                del zeilen
                rows = arcpy.InsertCursor(Bohrpunkt_fc)
                for Punkt in Punkteliste:
                    feature = rows.newRow()
                    feature.shape = Punkt
                del rows, Punkteliste
                print "Die Punkt-Geometrien fuer die Featureclass 'BF_Stao_Bodenprofil_P'      wurden erstellt."
                Liegenschaftsnummer = dataset[1:8]
                arcpy.AddField_management (Bohrpunkt_fc, "Lgs_Nummer", "TEXT", "", "", 7)
                arcpy.AddField_management (Bohrpunkt_fc, "Profil_ID", "TEXT", "", "", 12)
                arcpy.AddField_management (Bohrpunkt_fc, "Profil_Nr_alt", "TEXT", "", "", 4)
                arcpy.AddField_management (Bohrpunkt_fc, "Profiltyp", "SHORT", 1)
                arcpy.AddField_management (Bohrpunkt_fc, "Standortseinheit", "TEXT")
        del Bohrpunkt_fc        
    del listDatasets



I had some tries to solve my Problem:

First, I made a Batch-Script-tool out of my standalone Script. As before, the script is processed for my first Dataset, but not for the following. Now I get a "serious application error" and the script is interrupted.

So, my second try was to discard the idea of processing my Data in all Dataset by looping through them/ using a Batch and instead using a simple script-tool, where i have to set the workspace individually for every dataset. After using the script for the first dataset, I open it again, set the workspace to the second an start it again, and -what a surprise - the same error occurs again. I first have to close ArcCatalog before i can start the script again....

Can this indicate, that there is some lock remaining, after the script is terminated? I delete every single reference before the script ends and delete temporary featureclasses.

Any advice? Or has someone else experienced this before?

  • Could you post your script please? – Aaron Sep 12 '12 at 12:53
  • change line 6 to "arcpy.env.workspace = workspace" and line 13 to "out_name = "BF_Stao_Bodenprofil_P_" + dataset". Hope that will work for you. – iRfAn Sep 12 '12 at 15:40

I was able to replicate a problem with your script, though without the Windows "this program must be terminated" dialogs. It took a bit of sleuthing to get to the bottom of it, but in a nutshell out_name = "BF_Stao_Bodenprofil_P_" + dataset[9:] is creating duplicate feature class names.

FC's must be unique in a geodatabase, even when in different feature datasets. Once I changed that line, the script would finish successfully. My working script is here.

The changes of note are:

Using try: ... except: to report the Arcgis generated errors. Without that Arcgis will often just quit with no visible error at all. For a full description see Error handling with Python. Don't let the length of that page scare you! This is often good enough:

    print 'About to run CreateFeatureClasses...'
    print 'Exception Messages:\n', arcpy.GetMessages()

This change yield the slightly more informative error below, so at least I could determine where it stopped, even if not exactly why:

Exception Messages:
Executing: CreateFeatureclass c:\temp\test.gdb\two BF_Stao_Bodenprofil_P_ POINT # DISABLED DISABLED # # 0 0 0
Start Time: Mon Sep 17 15:34:56 2012
ERROR 999999: Error executing function.
Failed to execute (CreateFeatureclass).
Failed at Mon Sep 17 15:34:57 2012 (Elapsed Time: 1.00 seconds)`

After that it was a matter of sprinkling statements like print 'Outname:', out_name to get to the bottom.

| improve this answer | |
  • I thank you very much for your effort! I really have to apply this error-handling stuff to my scripts from now on. Anyway, I don't think, thats it's a point of creating FCs with identical names, because the statement " + dataset[9:]" generates unique featureclassnames. I'd really like to know what the problem was, but i already solved my work with a more "manual approach". Anyway, thank you all :) – Sebastian Sep 18 '12 at 6:25

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