Boolean Checkbox Python Code Help

3333
2
09-04-2014 11:58 AM
JamesDuBois
New Contributor II

I have created a model that has an optional input for start times (time of day) for an OD Cost Matrix. I have two check boxes, one for am rush (8:00:00 AM) and one for pm rush (5:00:00 PM). I am trying to get the start time as an input to the OD Cost Matrix but am unsure of how Boolean code would work. Here is a photo of what I have so far. I am cringing asking this because I know I am being unclear... I just can't formulate the proper question? Capture.JPG

0 Kudos
2 Replies
NtriankosIoannis
New Contributor II

Hi James,

I haven't use OD Cost Matrix, but if I get this right, you want the user to determine a time and then use this time as a variable in OD Cost Matrix. If that's the case you can just use a list and the user will select the proper time(in model properties-> parameters tab, set a list with the two values for the string parameter)... no need of booleans...

If you insist following a more complex way... this should look like this:

Set the two string variable  (in model properties-> parameters tab, set the parameters as optional). Then do what you have already done and use merge branch with the two booleans as input. Merge branch output is the user input and can be used as a variable in od cost matrix.

But ... there is no need of that.

Greetings,

John

0 Kudos
GerryGabrisch
Occasional Contributor III

But if you wanted to code a Boolean check box in a scripting tool using Python and ArcToolbox you would do something like this.

myboolean = arcpy.GetParamterAsText(0)

When you add the script to a ArcToolbox scripting tool you would define the parameter as type Boolean.

Depending on whether the checkbox is checked or not, myboolean would have a value of "true' or 'false'.

Then you could do something like

if myboolean =='true':

    your code here...