I have built a loop that creates each time a series of features (lines). And every time that new features are created I want to save them into a feature class (always the same one).

I believe I need to use Append_management to do this. The problem is that the target feature class will initially be empty and therefore the first time the script is trying to append things to it I get an error stating that it doesn't exist.

#Import geoprocessing.
import arcpy
import os

#sys.path[0] gives us the folder where the script is. Then we have to go up one level in the folder structure
#(first we build the path to the parent directory and then we need to normalise it
working_folder = os.path.normpath(os.path.join(os.path.dirname(__file__), '..'))

#Input variables.
fc_Opt_All = os.path.join(working_folder, 'DATA\Optimity_Equipment.gdb', 'Optimity_All')

#Building all existing Wibre links
#Selecting features from Optimity_All where 'LINK' field is not blank and saving them into a feature class
arcpy.MakeFeatureLayer_management(fc_Opt_All, 'fl_Opt_All') 
query = "LINK NOT LIKE ''"
arcpy.SelectLayerByAttribute_management('fl_Opt_All', 'NEW_SELECTION', query)
fc_airB = os.path.join(working_folder, 'DATA\Optimity_Temp.gdb', 'airB')
arcpy.CopyFeatures_management ('fl_Opt_All', fc_airB)

#Building all links between airA (indicated in field 'LINK') and airB
fc_links = os.path.join(working_folder, 'DATA\Optimity_Temp.gdb', 'links')
with arcpy.da.UpdateCursor(fc_airB, field_names) as cursor_1:
    for row_1 in cursor_1:

        arcpy.MakeFeatureLayer_management(fc_airB, 'fl_airB') 

        #Selecting airB 
        query = "LOCATION = '{}'".format(row_1[0])
        arcpy.SelectLayerByAttribute_management('fl_airB', 'NEW_SELECTION', query)

        #Selecting airA 
        arcpy.MakeFeatureLayer_management(fc_Opt_All, 'fl_Opt_All') 
        query = "LOCATION like '{}%'".format(row_1[14])
        arcpy.SelectLayerByAttribute_management('fl_Opt_All', 'NEW_SELECTION', query)

        #Building the line between the pair
        fc_link = os.path.join(working_folder, 'DATA\Optimity_Temp.gdb', 'link')
        arcpy.ddd.ConstructSightLines ('fl_airB', 'fl_Opt_All', fc_link, 'OFFSETC', 'OFFSETC')

        arcpy.Append_management(fc_link, fc_links)

The error message I get is:

Traceback (most recent call last):
  File "C:\ESRI\ArcGIS_Pro_Projects\Optimity_Alf\Arcpy_Scripts\Affected_LOS.py", line 43, in <module>
    arcpy.Append_management(fc_link, fc_links)
  File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\management.py", line 3984, in Append
    raise e
  File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\management.py", line 3981, in Append
    retval = convertArcObjectToPythonObject(gp.Append_management(*gp_fixargs((inputs, target, schema_type, field_mapping, subtype), True)))
  File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\geoprocessing\_base.py", line 506, in <lambda>
    return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.
 ERROR 000732: Target Dataset: Dataset C:\ESRI\ArcGIS_Pro_Projects\Optimity_Alf\DATA\Optimity_Temp.gdb\links does not exist or is not supported
Failed to execute (Append).
 Failed to execute (AffectedLOS).

Any idea on how to get this working?

  • 8
    You need to create it using CreateFeatureclass_management. An option to append is the da insertcursor but you still need to create it first. – BERA Feb 27 '18 at 13:11
  • 2
    You define the path but never create fc_links feature class. – Ben S Nadler Feb 27 '18 at 13:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.