Select to view content in your preferred language

Batch Processing in Model Builder - Delete rows then Append

5724
14
02-25-2016 03:21 PM
SanhitaChatterjee1
Deactivated User

I am trying to delete rows from multiple feature classes with prefix TCEMaster_* (such as TCEMaster_Centerline, TCEMaster_Fence etc.) in TCEMaster.SDE ----then append the feature classes with data from another sde. Names of the feature classes in Input dataset is without the prefix (such as Centerline, Fence etc.).

My ultimate goal is to run a script/batch file routinely.

Should I use modelbuilder with Iterator and then export to python or a script in python. I am not much of an expert in python. See attached what I got started in modelbuilder.  I  have also attached a screenshot of the databases exported to FGDB  for testing purposes. Target dataset is TCEMaster in test_TCE.gdb and input dataset is R0007199 in test.gdb.

Any help will be highly appreciated.

0 Kudos
14 Replies
MichaelVolz
Esteemed Contributor

Start with model builder for 1 feature class and then export out to python.  Python has some great tools for iterating.

0 Kudos
SanhitaChatterjee1
Deactivated User

Can you please tell me what parameter is missing here in the python iterator?

Input dataset is Temp_test.gdb\\R0007199

Target dataset is test_TCE.gdb\TCEMaster

Target dataset has a wildcard TCEMaster_*

Both datasets have same schema- only difference is the wildcard in target dataset.

# Import arcpy module

import arcpy

arcpy.env.workspace = "C:\Users\sc\Desktop\test\test_TCE.gdb\TCEMaster"

fcs = arcpy.ListFeatureClasses("TCEMaster_*")

Inputdataset = "C:\\Users\\sc\\Desktop\\test\\Temp_test.gdb\\R0007199"

Targetdataset = "C:\Users\sc\Desktop\test\test_TCE.gdb\TCEMaster"

# Process: Append

for fc in Inputdataset:

    arcpy.Append_management(fc, fcs, "TEST", "", "")

0 Kudos
MichaelVolz
Esteemed Contributor

Do you want to process all feature classes in a file geodatabase?

Or are you trying to process all feature classes in a specific feature dataset in a file geodatabase?

0 Kudos
SanhitaChatterjee1
Deactivated User

Specific feature dataset "TCEMaster" and all FCs in this feature dataset

0 Kudos
MichaelVolz
Esteemed Contributor

# Process: Append

for fc in Inputdataset:

    arcpy.Append_management(fc, fcs, "TEST", "", "")

Instead of for fc in Inputdataset:

for fc in arcpy.ListFeatureClasses('*','All',Inputdataset):

0 Kudos
SanhitaChatterjee1
Deactivated User

Thanks Michael.

It works if I do not have a wildcard set (such as without "TCEMaster_*" in target dataset). When I have the wildcard defined I get an error:

File "C:/Users/sc/Desktop/test/Append_Iterator_Export_Test.py", line 25, in <module>

    for fc in arcpy.ListFeatureClasses('*','All',Inputdataset):

TypeError: 'NoneType' object is not iterable

This is what I have now:

# Import arcpy module

import arcpy

arcpy.env.workspace = "C:\Users\sc\Desktop\test\test_TCE.gdb\TCEMaster"

fcs = arcpy.ListFeatureClasses("TCEMaster_*")

Inputdataset = "C:\\Users\\sc\\Desktop\\test\\Temp_test.gdb\\R0007199"

Targetdataset = "C:\Users\sc\Desktop\test\test_TCE.gdb\TCEMaster"

# Process: Append

for fc in arcpy.ListFeatureClasses('*','All',Inputdataset):

    arcpy.Append_management(fc, fcs, "TEST", "", "")

0 Kudos
MichaelVolz
Esteemed Contributor

Are you trying to access multiple feature datasets in your code and then all feature classes in all the feature datasets?

Or do you just want to iterate all feature classes in one feature dataset?

0 Kudos
SanhitaChatterjee1
Deactivated User

Michael, It is all feature classes in one dataset.

0 Kudos
MichaelVolz
Esteemed Contributor

Then if the code without the wildcard runs without error, that should do the trick for you.  Now if you want to automate this, just add the python script to Windows Task Scheduler.

0 Kudos