3

I have some dataset topologies that I want to loop through, but I need to test for the assignment of feature classes so the scripts don't fail. (Using Win 7, ArcGIS 10.2, Python 2.7.5 and a file GDB)

My research hasn't turned up too much but using the 10.2 "Remove Feature Class From Topology (Data Management)", using ArcCatalog I can remove an existing fc from the topo set. If however I run the script 'stand alone' and the fc isn't currently assigned to the topology, the script fails. (Error shown below script)

I read this post (ArcMap remove feature-class from feature-dataset) as well but I don't want to delete the fc, I only want to remove it from the topo if it exists as I need it again later.

Am I going down the wrong path?

Using ArcCatalog, this succeeds if the fc exists;
topo = "C:/Data/Terrain_36/TOPO_EXPORT_2015_09_09_1_2.gdb/ZONES_1_2/TOPO_1_2"
fc = "RL_10"
arcpy.RemoveFeatureClassFromTopology_management(topo, fc)

# Running the script below as 'stand alone', fails if the fc isnt currently assigned;
# import modules
import arcpy, sys, os, datetime, traceback, string, time
from os import sep, listdir
from arcpy import env  as env

# This scripts name
script_name = os.path.basename(sys.argv[0])
# Create file prefix for unique file naming
prefix = datetime.datetime.now().strftime('%Y-%m-%d %H%M')
# Create file suffix for avoiding filenames staring with numbers
suffix = datetime.datetime.now().strftime('%Y-%m-%d %H%M')

# Set variables
Top_Dir = "C:/Data/Terrain_36"
td = Top_Dir
print "Top_Dir set to: '" +td+ "'" + '\n'
# Out_Dir = td+sep+ 'Exports'
# print "Out_Dir set to: '" +Out_Dir+ "'" + '\n'
Log_Dir = td+sep+ 'zz_logs'
print "Log_Dir set to: '" +Log_Dir+ "'" + '\n'
GDB_Nam = 'TOPO_EXPORT_2015_09_09_1_2.gdb'
print "GDB_Nam set to: '" +GDB_Nam+ "'" + '\n'
GDB_Home = os.path.join(td, GDB_Nam)
print  "GDB_Home set to: '" +GDB_Home+ "'" + '\n'

# Set the workspace environment
env.workspace = os.path.join(Top_Dir, GDB_Nam)
ws = env.workspace
print "Env.workspace set to: '" +ws+ "'" '\n'
topo = "C:/Data/Terrain_36/TOPO_EXPORT_2015_09_09_1_2.gdb/ZONES_1_2/TOPO_1_2"
fc = "RL_10"
if arcpy.Exists (fc):
    arcpy.RemoveFeatureClassFromTopology_management(topo, fc)

# My error messages
Log: 2015-09-14 11:48:32.722000
Begin process: Topo_script.py
 Process started at 2015-09-14 11:48:32.722000
 PYTHON ERRORS:
 Traceback info:
   File "C:\Data\Terrain_36\Data_quality\_Scripts\Topo_script.py", line 62, in <module> arcpy.RemoveFeatureClassFromTopology_management(topo, fc)
 ArcPy ERRORS:
 ERROR 999999: Error executing function.
 Cannot register as versioned on this database.
 Cannot register as versioned on this database.
 Failed to execute (RemoveFeatureClassFromTopology).
  • 1
    To be part of a topology the feature class should be in a feature dataset, your value topo isn't a feature dataset... Can you insert a screen shot of your full path to topology and feature classes in catalog please. – Michael Stimson Sep 14 '15 at 2:52
  • Yes, it is in fact part of a feature dataset. Unfortuantely I cant do screen shot stuff at work (Gov dept) but have updated the path above. – user1995458 Sep 14 '15 at 2:59
  • 1
    Yes, it is in fact set earlier within a much larger script. Unfortunately it will only further confuse things if I post the entire code but I will add it to my snippet above for completeness. It isnt why it doesnt run but I do appreciate your input. – user1995458 Sep 14 '15 at 3:47
  • 1
    I can see there's more lines as the error occurs on line 62... the error is about versioning, not about arcpy.Exists, is this a checkout version (replica)? Your workspace isn't quite right, you (might) need the feature dataset in there as well... geodatabases can be a bit funny like that. env.workspace = os.path.join(Top_Dir, GDB_Nam, "TOPO_1_2") try that and see if it helps. – Michael Stimson Sep 14 '15 at 3:53
  • 1
    Yes, it's one of those funny things in a database/feature dataset. Exists returns true if the feature class is in the database somewhere, either standalone or in a feature dataset, but to correctly locate the feature class you need to include the feature dataset in the path. Sometimes you can get away without it but a lot of the time you can't... – Michael Stimson Sep 14 '15 at 4:05
2

Why not use arcpy.Describe on the topology itself and see if the featureclass is in the featureClassNames attribute?

Something simple like:

if fc in arcpy.Describe(topo).featureClassNames:
    arcpy.RemoveFeatureClassFromTopology_management(topo, fc)
else:
    print "{0} wasn't in the topology...".format(fc)
| improve this answer | |
  • 1
    Absolutely fabulous thanks @Evil-genius. That achieves my goal precisely and was an option I had not thought of. – user1995458 Sep 14 '15 at 22:18

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.