HOW TO

Automate adding GlobalIDs

Last Published: April 25, 2020

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

Article ID:000011755

Software:
  • ArcMap

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Discover more on this topic