I am trying to write a script that copies the schema (no data) for multiple feature classes from one geodatabase to another (in this case SDE to File Geodatabse). I'm not copying all feature classes, but a list of them.
The only way I've been able to find that will allow me to copy the schema to another database is using arcpy.ExportXMLWorkspace_management()
and then arcpy.ImportXMLWorkspace_management()
for each feature class.
import arcpy, os
workspace = r"D:\Processing\myGDB"
myGDB = os.path.join(workspace, "TempGDB.gdb")
sdeDB = r"Database Connections\Geodatabase.sde"
fcList = [['Layerone'], ['LayerTwo'], ['LayerThree'], ['LayerFour']] # See note below!
for x in fcList:
fc = x[0]
xmlFile = os.path.join(workspace, "{}.xml".format(fc))
arcpy.ExportXMLWorkspaceDocument_management(os.path.join(sdeDB, fc), xmlFile, "SCHEMA_ONLY", "BINARY", "METADATA")
arcpy.ImportXMLWorkspaceDocument_management(myGDB, xmlFile, "SCHEMA_ONLY", "")
arcpy.Delete_management(xmlFile)
This process is quite long-winded, as it has to step through each feature class, export the schema from geodatabase 1 to an XML file, import from that XML into geodatabase 2, and then delete the XML file.
Is there a tool or function within ArcGIS Desktop that will allow me to copy the schema to another geodatabase for selected feature classes without having to loop through them one at a time?
Note: The fcList
is a list of lists as in the actual script it performs a SQL query to get the list of feature classes, and this is returned as a list of lists.