Can you link the first precondition to the second precondition (so the first precondition must be true before the second fires) then link both (or just the second) to the final process?
Perhaps you can use If-Then-Else logic as output from your "Sum Field Insert New" process, and then link the output variable as the precondition to 'Altered Input?"
In ModelBuilder, if-then-else logic can be implemented by writing a
script tool that tests some condition, then outputs two Boolean
variables that describe the true and false condition and incorporating
this script tool in a model. As an alternative to writing a script
tool, you can also use the Calculate Value tool to test the condition
and output a Boolean.
... One of the key steps in using branching logic in ModelBuilder is setting one of the conditional outputs as a precondition to further processing.
The Check Is Not Actually Required If You are Going to Create The Field Anyhow
If you are going to create the field if it doesn't exist, you don't even need to check for its existence. If the field already exists, and you run arcpy.AddField_management()
for that same field, it will do nothing.
Similarly in ModelBuilder if you run the 'Add Field' tool, it will output a message warning that the field already exists, but it will continue on to the next step in the model just fine. (NB: If you do it with a different data type, it will fail, but so long as you use the same data type, it is fine.) Subsequent tools in the model that depend on that field should then be able to validate successfully, because the model can determine that the field will actually exist. Creating the field with a script tool will not allow the model to validate the existence of that field. So with your script tool method the model may be able to run successfully if you run it directly (ie, not in edit mode) but it won't be able to validate and run in edit mode.
I can't see this behaviour of the 'Add Field' tool and arcpy.AddField_management()
function documented anywhere, but I noticed it a while back and have found it to be useful.
Of course you would need to be confident that if the field already exists, that it will be of the correct data type, length, etc.
To confirm, I just ran the following code:
print "Adding new field first time"
arcpy.AddField_management(fc, "NewField", "TEXT")
print "Adding new field second time"
arcpy.AddField_management(fc, "NewField", "TEXT")
print "Adding new field third time"
arcpy.AddField_management(fc, "NewField", "TEXT")
and got the following output:
Adding new field first time
Adding new field second time
Adding new field third time
The new field was added to the fc
feature class and no errors were reported.
I then ran a model in ModelBuilder that adds a field that already exists and then does a Calculate Field on that same field and it worked fine. I got the output:
Executing (Add Field): AddField C:\Users\<username>\Documents\ArcGIS\Default.gdb\fc NewField TEXT # # # # NULLABLE NON_REQUIRED #
Start Time: Tue Aug 21 11:01:38 2018
WARNING 000012: NewField already exists
Succeeded at Tue Aug 21 11:01:38 2018 (Elapsed Time: 0.08 seconds)
Executing (Calculate Field): CalculateField C:\Users\<username>\Documents\ArcGIS\Default.gdb\fc NewField 'blah' PYTHON #
Start Time: Tue Aug 21 11:01:38 2018
Succeeded at Tue Aug 21 11:01:38 2018 (Elapsed Time: 0.12 seconds)
It's up to you whether you want to be extra safe and do the check anyhow, but at least in version 10.3.1 and 10.5.1 that I've used recently, it works fine this way. It's quite convenient behaviour (at least for this kind of scenario).
If a Field Existence Check Really Is Required
There are some situations when you really do need to check for the existence of a field (eg, you don't want to create a new field, but you do want to do something different depending on if the field exists or not). In this case, I use something like:
if len(arcpy.ListFields(fc, fieldName)):
# Field exists. Do something.
else:
# Field does not exist. Do something else.
Best Answer
As @PolyGeo mentioned, add a fourth parameter to your script tool with the following properties:
Then, in your script, build up a list of paths to your output rasters. Upon completion, join them as a semicolon delimited string and pass that to
SetParameterAsText
to set the derived parameter.You should then be able to directly connect the script tool to the Polygon to Raster tool.