Append feature classes using Python

5417
16
Jump to solution
07-05-2018 06:53 AM
EdwardGlover1
New Contributor III

I have 5 point feature classes that I am trying to append into a point feature class.  I get the following error when I attempt to run the code shown below: 

Failed to execute. Parameters are not valid.
ERROR 000338: Inputs must be either all Feature Classes, Tables or Rasters; not mixed.
Failed to execute (Append).

I can run the append successfully when using the Append tool in Desktop.  I am at a loss as to why the code throws the error.  Any insight would be very much appreciated.

# Import arcpy module
import arcpy
import os


SDE = r'C:\Development\py1\gis@GISDEV02 frt (emadb51 DC) - VegD2.sde'

# Set local variables
FC_Inven = os.path.join(SDE, 'GIS.VegD_Inventory')
FC_Unit = os.path.join(SDE, 'GIS.VegD_Unit_Inventory')
FC_Hrly2 = os.path.join(SDE, 'GIS.VegD_Hourly_Inventory')
FC_Hrly = os.path.join(SDE, 'GIS.VegD_Hourly')
FC_Flat = os.path.join(SDE, 'GIS.VegD_FlatRate')
FC_Matrix = os.path.join(SDE, 'GIS.VegD_Matrix')
schemaType = "NO_TEST"
fieldMappings = ""
subtype = ""

try:

    # Process: Truncate Table
    arcpy.TruncateTable_management(FC_Inven)

    # Process: Append the feature classes into the empty feature class
    arcpy.Append_management('FC_Unit; FC_Hrly2; FC_Hrly; FC_Flat; FC_Matrix', FC_Inven, schemaType,    fieldMappings, subtype)

except Exception as err:
print(err.args[0])

Tags (2)
16 Replies
EdwardGlover1
New Contributor III

Unfortunately, I get the same error message when I try this approach as well. 

0 Kudos
DarrenWiens2
MVP Honored Contributor

The help example uses a list for the feature classes, not a delimited string.

Append—Data Management toolbox | ArcGIS Desktop 

0 Kudos
DanPatterson_Retired
MVP Emeritus
0 Kudos
DarrenWiens2
MVP Honored Contributor

Ah, so it was. I thought you meant comma-delimited string. You can't make a list any other way 

0 Kudos
EdwardGlover1
New Contributor III

I get the same ERROR 000338 when I copied the feature classes to a fgdb and modified the code to reference it and run it.  I then tried using the Append tool and navigating to the fcs within the tool to add them with their entire fgdb path - it ran successfully.  I went to the results, right-clicked and copied as code snippet.  I took the input and target syntax from that code and replaced my append input and target parameters with it and ran the code - it worked successfully.  I repeat these steps with a database connection and was successful.

arcpy.Append_management("'C:/Development/py1/gis@GISDEV02 frt (emadb51 DC) - VegD2.sde/GIS.VegD_FlatRate';'C:/Development/py1/gis@GISDEV02 frt (emadb51 DC) - VegD2.sde/GIS.VegD_Hourly';'C:/Development/py1/gis@GISDEV02 frt (emadb51 DC) - VegD2.sde/GIS.VegD_Matrix';'C:/Development/py1/gis@GISDEV02 frt (emadb51 DC) - VegD2.sde/GIS.VegD_Hourly_Inventory';'C:/Development/py1/gis@GISDEV02 frt (emadb51 DC) - VegD2.sde/GIS.VegD_Unit_Inventory'", "C:/Development/py1/gis@GISDEV02 frt (emadb51 DC) - VegD2.sde/GIS.VegD_Inventory", schemaType,    fieldMappings, subtype)

I still don't know why when I attempt to clean this line of code up using variables, it results in the ERROR 000338.

0 Kudos
DanPatterson_Retired
MVP Emeritus

perhaps there is some internal workings that handle the punctuation and spaces that isn't activated through arcpy calls to the tool directly

0 Kudos
EdwardGlover1
New Contributor III

The error was caused by the Append input being interpreted as a string as opposed to variables.  Below is syntax that worked for me.  Thanks to all for your assistance with my issue!

arcpy.Append_management('"' + FC_Unit + ';' + FC_Hrly2 + ';' + FC_Hrly + ';' + FC_Flat + ';' + FC_Matrix + '"', FC_Inven, schemaType,    fieldMappings, subtype)
0 Kudos