Append error in script

1192
2
10-31-2012 11:59 AM
AnthonyTimpson2
Occasional Contributor
EDIT: I figured it out.. apparently if there is data in the TOC it gets confused. By deleting the data from the TOC on each run through the loop i was able to get the append operation to work... odd problem with a simple solution.

Thanks for taking a look, here is the updated  main for loop

 for mdb in mdbList:  env.workspace = destSpace  destList = arcpy.ListFeatureClasses()    print "Dest Length = " + str(len(destList))  tempSpace = mxdPath.replace("SetupRUN.mxd", mdb)  env.workspace = tempSpace  fcList = arcpy.ListFeatureClasses()  print "Destination MDB - " +str(destSpace)  print "Source MDB      - " + str(tempSpace)   if len(destList) == 0:   for fc in fcList:    arcpy.Copy_management(fc, destSpace + "\\"+fc)    print "copied FC - " +str(fc)    elif len(destList) >=1:   for fc in fcList:    for dest in destList:     if fc == dest:      print "Source FC      - "+ fc      print "Destination FC - "+ dest      print "Destination location - "+ destSpace + "\\" + fc      arcpy.Append_management([fc], destSpace + "\\" + fc, "NO_TEST" , "" , "")  for df in arcpy.mapping.ListDataFrames(mxd):   for lyr in arcpy.mapping.ListLayers(mxd,"",df):    arcpy.mapping.RemoveLayer(df, lyr)


Hi.

I am working on a bit of python to merge many MDB worth of FC into a new freshly created MDB. For the most part they are the same.

the error is ERROR 000572: The output cannot be the same as input. Failed to execute (Append)

I have been trying to reconcile this error for the better part of a few days with no luck. I am almost positive that the source and destination are different things.

OUTPUT WINDOW::
Destination MDB - C:\Users\atimpson\Desktop\MDB Combiner\Combined.mdb
Source MDB      - C:\Users\atimpson\Desktop\MDB Combiner\20121008_Group_B_formatted.mdb
Runtime error <class 'arcgisscripting.ExecuteError'>: ERROR 000572: The output cannot be the same as input. Failed to execute (Append).

import os import arcpy import time from arcpy import env   mdbList=[] sizeList = [] mxd  = arcpy.mapping.MapDocument("CURRENT") mxdPath  = mxd.filePath workSpace = mxdPath.replace("\SetupRUN.mxd", "") print workSpace env.workspace = workSpace dirlist=os.listdir(workSpace)  for item in dirlist:     if item.lower().endswith("mdb"):         print item         mdbList.append(item)  arcpy.CreatePersonalGDB_management(workSpace, "Combined.mdb") destSpace  = mxdPath.replace("SetupRUN.mxd", "Combined.mdb") env.workspace = destSpace destList = arcpy.ListFeatureClasses() print "Destination Contents = " + str(destList)  for mdb in mdbList:  env.workspace = destSpace  destList = arcpy.ListFeatureClasses()  print "Dest Length = " + str(len(destList))  tempSpace = mxdPath.replace("SetupRUN.mxd", mdb)  print "Database = " + tempSpace  env.workspace = tempSpace  fcList = arcpy.ListFeatureClasses()  if len(destList) == 0:   for fc in fcList:    arcpy.Copy_management(fc, destSpace + "\\"+fc)    print "copied FC - " +str(fc)    elif len(destList) >=1:   for fc in fcList:    for dest in destList:     if fc == dest:      arcpy.Append_management([fc], destSpace + "\\" + fc, "NO_TEST" , "" , "")    print mdb  size = len(fcList)  sizeList.append(size)  print "FeatureClasses = " +str(fcList)  print "FC count = " + str(size)  print "" print sizeList print "Number of Databases to be Merged = " +str(len(sizeList))
Tags (2)
0 Kudos
2 Replies
MathewCoyle
Frequent Contributor
Try using the described name instead of the list object for the output fc name.

for fc in fcList:

    desc = arcpy.Describe(fc)
    fcOut = os.path.join(destSpace, desc.name)

 for dest in destList:
  if fc == dest:
   arcpy.Append_management([fc], fcOut, "NO_TEST" , "" , "")
AnthonyTimpson2
Occasional Contributor
fortunately the changes were accepted, unfortunately they brought about the same error

Runtime error <class 'arcgisscripting.ExecuteError'>: ERROR 000572: The output cannot be the same as input. Failed to execute (Append).

I am now printing out what should be appending to what and where.. everything seems ok.. this problem is really confounding.

OUTPUT::

Destination MDB - C:\Users\atimpson\Desktop\MDB Combiner\Combined.mdb
Source MDB      - C:\Users\atimpson\Desktop\MDB Combiner\20121008_Group_B_formatted.mdb
Source FC      - main
Destination FC - main
Destination location - C:\Users\atimpson\Desktop\MDB Combiner\Combined.mdb\main
Runtime error <class 'arcgisscripting.ExecuteError'>: ERROR 000572: The output cannot be the same as input. Failed to execute (Append).

import os
import arcpy
import time
from arcpy import env


mdbList=[]
sizeList = []
mxd  = arcpy.mapping.MapDocument("CURRENT")
mxdPath  = mxd.filePath
workSpace = mxdPath.replace("\SetupRUN.mxd", "")
print workSpace
env.workspace = workSpace
dirlist=os.listdir(workSpace)

for item in dirlist:
    if item.lower().endswith("mdb"):
        print item
        mdbList.append(item)

arcpy.CreatePersonalGDB_management(workSpace, "Combined.mdb")
destSpace  = mxdPath.replace("SetupRUN.mxd", "Combined.mdb")
env.workspace = destSpace
destList = arcpy.ListFeatureClasses()
print "Destination Contents = " + str(destList)

for mdb in mdbList:
 env.workspace = destSpace
 destList = arcpy.ListFeatureClasses()
 print "Dest Length = " + str(len(destList))
 tempSpace = mxdPath.replace("SetupRUN.mxd", mdb)
 print "Database = " + tempSpace
 env.workspace = tempSpace
 fcList = arcpy.ListFeatureClasses()
 print "Destination MDB - " +str(destSpace)
 print "Source MDB      - " + str(tempSpace)

 if len(destList) == 0:
  for fc in fcList:
   arcpy.Copy_management(fc, destSpace + "\\"+fc)
   print "copied FC - " +str(fc)
 
 elif len(destList) >=1:
  for fc in fcList:
   desc = arcpy.Describe(fc)
   fcOut = os.path.join(destSpace, desc.name)
   for dest in destList:
    if fc == dest:
     
    # print "Source FC      - "+fc
    # print "Destination FC - "+ dest
    # print "Destination location - "+ destSpace + "\\" + fc
     arcpy.Append_management([fc], fcOut, "NO_TEST" , "" , "")
 
 print mdb
 size = len(fcList)
 sizeList.append(size)
 print "FeatureClasses = " +str(fcList)
 print "FC count = " + str(size)
 print ""
print sizeList
print "Number of Databases to be Merged = " +str(len(sizeList))

#for mdb in mdbList:
#for mdb in mdbList:
 
#print mdbList[0]
#tempSpace = mxdPath.replace("SetupRUN.mxd", mdbList[0])
#print tempSpace

#arcpy.CreatePersonalGDB_management(workSpace, "Combined.mdb")
#workSpace_2  = mxdPath.replace("SetupRUN.mxd", "Combined.mdb")
#arcpy.Append_management ([mdbList], workSpace_2,"NO_TEST","" ,"")
#arcpy.CreatePersonalGDB_management(workspace, "Combined.mdb")
0 Kudos