English

How To: Automate adding GlobalIDs

Summary

GIS Managers and administrators often need to prep data for replication in an automated fashion. One such preparation step is to add GlobalIDs. The below Python script provides an example of adding GlobalIDs to feature datasets and feature classes.

Procedure

Modify the workspace parameter according to your sde workspace:

workspace = r"C:\connections\Replicas\Replica1.sde"


Code:
import arcpy, os, string

def AddGlobalIDs_FC(workspace):
arcpy.ClearWorkspaceCache_management()
arcpy.env.workspace = workspace
try:
fcList = arcpy.ListFeatureClasses()
for fc in fcList:
arcpy.AddGlobalIDs_management(fc)
print "Added GlobalIDs to {0}".format(fcList)

except Exception as e:
print e.message

def AddGlobalIDs_FD(workspace):
arcpy.ClearWorkspaceCache_management()
arcpy.env.workspace = workspace
try:
fdList = arcpy.ListDatasets()
for fd in fdList:
arcpy.AddGlobalIDs_management(fd)
print "Added GlobalIDs to {0}".format(fd)

except Exception as e:
print e.message


if __name__== "__main__":
workspace = r"C:\connections\Replicas\Replica1.sde"
AddGlobalIDs_FC(workspace) #adds globalids to feature classes outside datasets
AddGlobalIDs_FD(workspace) #adds globalids to datasets