List of feature classes with ObjectID

3988
6
Jump to solution
05-26-2015 07:23 AM
CFrate
by
Occasional Contributor

I have a geodatabase that contains some stand-alone feature classes, and many feature datasets filled with more feature classes.

The GDB was created long ago without anyone to properly manage it, and there are many feature classes for which the OID field is named ObjectID_1, ObjectID_2, etc. Correcting this is a bridge I'll cross much later.

Each feature class contains a field called "ObjectID", whether it's the true OID field or not.

I want to identify all feature classes that have an OID field not called "OBJECTID". The method I was using was to make a list of all feature classes in the GDB, and then:

for f in fclist:
    desc = arcpy.Describe(sdeConn + os.sep + f)
    foid = desc.OIDFieldName
    if foid == "OBJECTID":
        fclist.remove(f)

This should remove all feature classes for which the OID field is named "OBJECTID", correct? Well, it removes some, but not all of those feature classes.

Thoughts and suggestions?

Thanks.

0 Kudos
1 Solution

Accepted Solutions
LukeWebb
Occasional Contributor III

Hows about this code: (Not indented properly)

#Create an empty list to store the BAD FCs in

BadFCs = []

for f in fclist:

    desc = arcpy.Describe(sdeConn + os.sep + f)

    foid = desc.OIDFieldName

    # If the filed is not the right one

    if foid != "OBJECTID":

        BadFCs.append(f)

#Print the outputs

for f in BadFCs:

     print (f)

View solution in original post

6 Replies
JeffWard
Occasional Contributor III

See this thread.

I think your script wouldn't take out any of your feature classes.  As I understand it, those ObjectID_n fields are no longer maintained by esri as the object ID, but are maybe left in the feature class in case you were using them for a relate or something?  I always use my own ID that I can control when doing relates and joins.

I think you can just delete those fields.

Jeff Ward
Summit County, Utah
CFrate
by
Occasional Contributor

Thanks, Jeff. Sorry if I wasn't clear.

I'm not treating them as OIDs or trying to join or get rid of them. I'll worry about that at a later date. I just need to identify all feature classes that contain a non-OID field called "OBJECTID".

For instance, feature class Roads may have an OID field called "OBJECTID_2", as well as two non-OID fields called "OBJECTID" and "OBJECTID_1", whereas Zoning may have only the proper "OBJECTID" as its OID field, and no others with an OBJECTID name. My resulting list would contain Roads, but not Zoning.

0 Kudos
LukeWebb
Occasional Contributor III

Hows about this code: (Not indented properly)

#Create an empty list to store the BAD FCs in

BadFCs = []

for f in fclist:

    desc = arcpy.Describe(sdeConn + os.sep + f)

    foid = desc.OIDFieldName

    # If the filed is not the right one

    if foid != "OBJECTID":

        BadFCs.append(f)

#Print the outputs

for f in BadFCs:

     print (f)

LukeWebb
Occasional Contributor III

Glad I helped, I have no idea what was wrong with your code, but it was possibly something like:

The feature classes:

FC1

FC2

FC3

Ok loop throught these FCs.

Check list[0]:

FC1 - it has Bad field name, remove from loop.  (List now looks like)

FC2

FC3

Next loop Item - check list [1]

list[1] = FC3

So it skipped FC2.

Hopefully that makes sense, although I could be wrong!

CFrate
by
Occasional Contributor

I found why it didn't always work. It was a capitalization issue. Some feature classes have the field "ObjectID" (as opposed to "OBJECTID"), which my script didn't identify.

0 Kudos
CFrate
by
Occasional Contributor

Thanks! Hadn't thought to try the opposite, but that did the trick.

0 Kudos