Python Code to find all Versioned Feature Classes within Enterprise Geodatabase

162
3
Jump to solution
07-08-2018 12:16 AM
BenVan_Kesteren1
Regular Contributor

Hey Everyone, 

I am wondering if anyone has got a simple script that they have that will iterate over all feature classes within my Enterprise Geodatabase, and return only the ones that are Registered as Versioned?

Sounds simple enough, I just haven't found an arcpy tool that will return versioned or not versioned.

Cheers

0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Esteemed Contributor

Ben, you might want to look through this thread.

The arcpy 'isversioned' is part of the 'describe' properties of a featureclass.

You need to cycle through the featureclasses and see if it meets the case

https://community.esri.com/message/782500-re-conditional-statement-unregisterasversioned?commentID=7... 

Dataset properties....

isVersioned
(Read Only)

Indicates whether the dataset is versioned.

Boolean

View solution in original post

3 Replies
DanPatterson_Retired
MVP Esteemed Contributor

Ben, you might want to look through this thread.

The arcpy 'isversioned' is part of the 'describe' properties of a featureclass.

You need to cycle through the featureclasses and see if it meets the case

https://community.esri.com/message/782500-re-conditional-statement-unregisterasversioned?commentID=7... 

Dataset properties....

isVersioned
(Read Only)

Indicates whether the dataset is versioned.

Boolean

View solution in original post

BenVan_Kesteren1
Regular Contributor

Exactly what I am looking for, thanks Dan.

0 Kudos
BenVan_Kesteren1
Regular Contributor

For anyone interested, below is the full code I used to do the following workflow:

  1. find all datasets within enterprise sde
  2. find only the datasets that have versioning applied
  3. ignore the dataset if it contains the string 'vegetation'
  4. unregister the dataset as being versioned

# set workspace
arcpy.env.workspace = r'Database Connections\GISADMIN@SDE_Spatial@SDE-DB.sde'

# build list of datasets
datasets = arcpy.ListDatasets()

#iterate over datasets
for dataset in datasets:
    # pull back information about the dataset
    description = arcpy.Describe(dataset)
    # ignore datasets that contain vegetation data
    if 'vegetation' not in dataset:
        # find if dataset is versioned
        if description.isVersioned:
            # unregister as versioned the dataset
            arcpy.UnregisterAsVersioned_management(in_dataset=dataset,
                                                   compress_default="COMPRESS_DEFAULT"
                                                   )

Thanks again for your help Dan.