Select to view content in your preferred language

Model Builder help

a month ago
Labels (2)
New Contributor III

Hoping to get help with model builder and a model I built.  I know there has to be an easier setup then the gigantic model I have.  Overall I'm trying to use the feature to feature tool to copy feature classes from one gdb to another and I'm doing this on a nightly basis. 

Before that copy occurs, I need to delete the existing feature classes in the gdb that will be copied to.  I understand there is an option to overwrite existing features but it doesn't work and I keep getting a copied feature class with '_1' after the 'parcelnum_1' since there's already a 'parcelnum' in there from previous update.

The model I built is extremely big and redundant, but that's from lack of experience and knowledge using model builder.  So again, what I need to do is copy feature class to feature class but delete the existing ones in the copy to gdb before the new ones are copied.

Please see attached photo of what I created and any help to streamline this process would be appreciated.  I have 3 different datasets with several feature classes in each.

I set it up to copy all the feature classes to gdb but before that, as a precondition, that each feature class is deleted first and than it copies.  Everything works fine, just wanting to see if there's an easier model process to follow.  Thanks for any help/guidance.


Copy Feature Classes.jpg

4 Replies
Esri Notable Contributor

David - so I looked into ModelBuilder, your model and perhaps a way of doing it better with iterators and a submodel embedded in the main model (typically you can only have 1 iterator per model but a sub-model allows you to have multiple iterators!). 

The first thing I did was create a new model (submodel) using the Iterate Feature Classes iterator.  I double clicked the Iterate Feature Class iterator and set the Workspace or Feature Dataset parameter to my fGBD that has the FC's I wish to delete. I set the Wildcard to an asterisk for all FC's.  I connected the green oval to the Delete GP tool.  Select all the graphical items in the model, right-click and click Group from the Context menu.  Next right-click again and select Save as Model and save it in your Custom Toolbox. (see Image 1)

Next, create a new model.  Drag and drop the newly created submodel onto the new model canvas.  I then added the Iterate Feature Classes iterator.  Double-click the Iterate Feature Classes iterator.  For Workspace or Feature Dataset parameter, navigate to your other GDB that has the new data to copy into the other GDB.  I set the wildcard parameter again with an asterisk for all FC's.

Next add the Copy GP tool to your model and connect the green oval to the Copy GP tool. (See Image 2)

Save your and name this model in your custom toolbox.  You should now have 2 toolboxes - 1 for the submodel and 1 for the main model.

The key to making this approach work is in the Catalog Pane under Databases, be sure to set your output geodatabase as the default geodatabase.  Right-click on the target GDB and select Make Default.

In the main model modelbuilder view, select validate and run from the run group on the ModelBuilder tab.  This workflow works for me and I think simplifies what you're trying to do.

Caveat - of course - Python is a better approach.  I can export this out as a Python script and tweak the script more.


0 Kudos
New Contributor III


I appreciate your time looking into this and helping.  While the initial model build was successful, it doesn't work when trying to re-run when I want to run an update each day.  I get an error message.

error message.JPG

Also, I don't like the fact of having to use the default gdb.  I all ready have 1 I need to use instead.  Not sure it would work using the one I created??  Overall, the process was way faster to complete though.  I'm going to try and tweak some things and see if I can get to work using your model format, but adjust some things.

I also have 3 datasets.  I assume I would recreate the initial model and just point to the other 2 datasets?  Thanks again.

0 Kudos
Esri Notable Contributor

@DavidAdelsberg  - you're welcome!  I've enjoyed working through this workflow!  I think I have a better understanding of the issue and a solution that mixes ModelBuilder and some Python.  Instead of worrying about Models and Submodels to run iterators (can only have one iterator per model but submodels do get around this issue, I decided to create 3 standalone models and 1 Python script tool in a Toolbox.

1.  The first model is the Delete Model.  It deletes all feature classes and feature datasets. The standalone Delete GP tool is hardcoded to delete the FDS in the target. See image below.

2.  The next model is the Copy Feature Class Model - this copies all FC's from the source geodatabase to the target geodatabase.  See image below.

3.  The next model copies the Feature Datasets from the source geodatabase to the target geodatabase.  The key with this one is using the %Name% inline variable for the output data parameter in the Copy GP tool.  This will use the name of the input FDS and copy an exact copy of the name in the target GDB.


4.  Next I created a simple Python script that calls the models sequentially.  See image below:

Lastly, in the project toolbox, I right-clicked on the toolbox and selected Script and fill out the tabs to point to the Python script.  This is now a Python Script tool you can rerun regularly.  I've tested it many times and there are no _1's or _2's present.  One last thing to double check is your Project->Options->Geoprocessing tab for the "Allow geoprocessing tools to overwrite existing datasets" is checked on.

Let me know what you discover from the process setting it to your enterprise geodatabase connections.

0 Kudos
New Contributor III

@Robert_LeClair Thank you again for taking the time to explore this.  I haven't had time yet to test this as I've been very busy with work.  I will try this out and report back to you and let you know how it worked.  Thanks again!