Different output from an ArcGIS Model depending on whether the model is run within model builder itself or through the toolbox dialog?

426
3
10-10-2018 03:27 PM
by Anonymous User
Not applicable

I wan't to create a model where at the end any empty outputs are automatically deleted. To do this I've tried a few things, mainly with python either through an embedded script tool or though python code in a calculate value tool. Everything seems to work fine when I run the model within model builder (Model > Run Entire Model), but as soon as I close the model and try running it through the dialog box (Toolbox > Double click on the model) way more feature classes are deleted then should be. I've been using a get count function where the input feature class is deleted if the number of features is 0. Can anyone think of why the results might be so different?

0 Kudos
3 Replies
curtvprice
MVP Esteemed Contributor

Are the output feature classes you are trying to delete output parameters? If so this makes sense to me that this would not be doable when running with a tool as outputs run as tools have layer objects generated (ie added to map) so file locking will not let you do that!

0 Kudos
by Anonymous User
Not applicable

Hi Curtis,

The output location is a parameter but not the individual feature classes. My problem is not that they aren't deleted, but that for some reason when I run from the toolbox dialog the tool deletes too many feature classes regardless of if they are empty or not - when I run it within the model builder window it performs correctly. Here's a look at the code of one of the methods I've tried. I have this run at the end of the model using the output folder parameter as the input workspace with creation of the feature classes as preconditions.

# Delete Empty Feature Classes in User Specified Workspace - Python Script
# Written By: Neal Banerjee, January 2013

# Import Python Modules
import arcgisscripting

#Create the geoprocessor object
gp = arcgisscripting.create(9.3)

# Set Workspace to list feature classes
#gp.workspace = "C:/temp/kme1.mdb/fdkme"

#Get Input Workspace as Argument
gp.workspace = gp.GetParameterAsText(0)


# Get List of Feature Classes in Workspace
lstFCs = gp.ListFeatureClasses()

print "\n"
gp.AddMessage("\n")
print "--------------------------------------------------"
#gp.AddMessage("--------------------------------------------------")
for fc in lstFCs:
print "Processing " + fc
gp.AddMessage("Processing " + fc)
recCnt = int(gp.GetCount_management(fc).GetOutput(0))
if recCnt == 0:
print "Empty - Deleting " + fc
gp.AddMessage("Empty - Deleting " + fc)
gp.Delete_management(fc)
else:
print str(recCnt) + " Records - Keeping " + fc
gp.AddMessage(str(recCnt) + " Records - Keeping " + fc)
print "--------------------------------------------------"
gp.AddMessage("--------------------------------------------------")
print "\n"
gp.AddMessage("\n")

0 Kudos
curtvprice
MVP Esteemed Contributor

Do you have the required preconditions set so your Calculate Value run (or embedded script) is forced to run last?

0 Kudos