Using Inline Variable Substitution with optional Parameter in ModelBuilder

arcgis-desktoparcgis-procalculate-valuesmodelbuildervariables

I am using ArcGIS Pro 3.0.3.

I have a model that is using inline variable substitution to pass a list of streets to my calculate value tool. This is an optional variable that is set as type Multiple Values [String], so the user may pass in nothing if they choose.

model

variable property

model property

I thought it would enter my function as None or empty string '', but if the parameter is blank then I see the variable name just gets entered as the string itself. For testing purposes, the code block below just returns the input parameter so I could see what value I got. In the real model, there are if / else statements to run different logic based on the input streets.

model message

If I add a test for st_to_exclude == "%Streets to Exclude%" inside the code block, then the inline variable substitution takes effect and whatever they entered will replace the "%Streets to Exclude%" in the code block, resulting in always true.

How do I test if the user passed in a value or left the variable empty? Or is there another workflow / function I should be using for this?

Best Answer

I think this may be a bug in the ArcGIS Pro ModelBuilder.

I created a model just like yours and tested the various scenarios of no value, 1 value, several. When I provided a value it all worked as expected. I then created a set of if/else statements in the calculate value tool and to my surprise only 1 test for "no value" actually works, this is what I had done:

def createwhereclause(s):
    if s is None:
        # Ignored!
        return "None!"
    elif s == "":
        # Ignored!
        return "Empty!"
    elif len(s) == 0:
        # Ignored!
        return "Zero!"
    elif "Streets" in  s:
        # This works!
        return ""
    else:
        # works when values are provided
        return "whereclause =" + s
Related Question