I need assistance writing a conditional statement that says if the dataset is already Unregistered to skip the balance and go directly to comp = arcpy.Compress_management(editDB)
Thank You in advance........Larry Adgate
import arcpy
editDB = "Database Connections\\Arden@gsw_sde.sde"
workspace = editDB
arcpy.env.workspace = workspace
#Need a conditonal Statment: if dataset is already UnregisterAsVersioned to go directly to comp
datasets = arcpy.ListDatasets("*", "Feature")
print datasets
for dataset in datasets:
fcList = arcpy.ListFeatureClasses("*","",dataset)
for fc in fcList:
print fc
arcpy.UnregisterAsVersioned_management(fc,"NO_KEEP_EDIT","COMPRESS_DEFAULT")
#if already Unregistered, skip the balance and go to below:
comp = arcpy.Compress_management(editDB)
datasets = arcpy.ListDatasets("*", "Feature")
for dataset in datasets:
fcList = arcpy.ListFeatureClasses("*","",dataset)
for fc in fcList:
arcpy.RegisterAsVersioned_management(fc, "NO_EDITS_TO_BASE")
Solved! Go to Solution.
Your if statement as written is looking for a feature class named 'Versioned'. Take a look at Dataset properties—ArcPy Functions | ArcGIS Desktop
You need to check :
arcpy.Describe(fc).isVersioned
# returns true if it is
if arcpy.Describe(fc).isVersioned:
do what you want
else
do something else
Larry can you format your code so people can check with the proper indentation
I apologize, here is my revised code with corrected indentations.......This script works except when I get to my conditional statement........My goal.....If a featureclass is already unregistered or is not versioned, the script needs to continue to the next featureclass w/o an error
import arcpy
editDB = "Database Connections\\Arden@gsw_sde.sde"
workspace = editDB
arcpy.env.workspace = workspace
datasets = arcpy.ListDatasets("*", "Feature")
print datasets
for dataset in datasets:
fcList = arcpy.ListFeatureClasses("*","",dataset)
for fc in fcList:
#My error begins below...
if fc == 'Versioned':
continue
print fc
arcpy.UnregisterAsVersioned_management(fc,"NO_KEEP_EDIT","COMPRESS_DEFAULT")
arcpy.Compress_management(editDB)
Runtime error Traceback (most recent call last): File "<string>", line 16, in <module> File "d:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\management.py", line 16702, in UnregisterAsVersioned raise e ExecuteError: ERROR 000131: The dataset is not versioned.
>>>
The if statement isn't indented properly... use the code formatting the link I sent.
Also you can't compare a featureclass (fc) to a text string. Was that the line you were using?
Your if statement as written is looking for a feature class named 'Versioned'. Take a look at Dataset properties—ArcPy Functions | ArcGIS Desktop
You need to check :
arcpy.Describe(fc).isVersioned
# returns true if it is
if arcpy.Describe(fc).isVersioned:
do what you want
else
do something else