Select to view content in your preferred language

If data exists does not work

2062
9
03-27-2021 03:23 PM
Labels (2)
StanislavaV
Emerging Contributor

HI!

I have large model made in ModelBuilder in ArcMap. First step is to create GDB where all of the outputs are saved. I need to the final output save in another output location. So I add "if data exists" this final output and I connect Yes (like precondition) with Delete that GDB. But it does not work.

When I run just Delete GDB - it works, but with those "if..." not.

What is the problem?

I know about scratch workspaces or in memory, but I need it this way in case it crash..

0 Kudos
9 Replies
curtvprice
MVP Esteemed Contributor

You can't delete objects that have been validated in ModelBuilder because there are file locks in play.

Have you tried using scratchGDB instead of in_memory? That way if you have a crash the scratch data will still be there after the model fails.

0 Kudos
StanislavaV
Emerging Contributor

I can´t figure it out. So I set the output location everywhere like C://User/username/Documents/scratch.gdb/base_name? Or C://User/username/Documents/%scratchGDB%/base_name? And then it should work? 

0 Kudos
curtvprice
MVP Esteemed Contributor

The model variable %scratchGDB% or %scratchFolder% will be replaced with a current writable location, normally a GDB or folder named scratch in the current project folder. For details, see the help for these environment variables. 

0 Kudos
StanislavaV
Emerging Contributor

didn´t work either. i don´t understand why is that when it is connected like "if data exists" in model, it won´t delete. but when i run model just for deleting, it works. i wanted to make it like "after model finish, than delete gdb"

StanislavaV_0-1616939089568.png

 

0 Kudos
curtvprice
MVP Esteemed Contributor
The issue is file locking. When you create or access data in your gdb, layers are created in memory that are pointing to your data and create a file lock that prevents deleting. Are you deleting all the layers and data before trying to delete the workspace? Even if you do that it can be challenging.
0 Kudos
StanislavaV
Emerging Contributor

yes i tried it. nothing again. i am thinking maybe about creating submodel? or i will give up and create another model just for "cleaning up" 🙂

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

If you simply want to delete the file geodatabase if it exists, using Exists is unnecessary because Delete returns success whether the file geodatabase exists or not.  Delete will return a warning if the geodatabase does not exist, but it returns "success" whether the GDB exists or not.

StanislavaV
Emerging Contributor

yes I know, but that model is based on: 

when output of copy features "ID" is created and saved in another gdb (not Ka.gdb), after then it can delete Ka.gdb. that is why i include that "if exist" 

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Ah, OK, I thought you were checking for the existence of the GDB you were deleting and not another GDB.

0 Kudos