Writing a tool within a Python toolbox I ran into the problem of checking the status of some checkbox.
While setting a default value for the checkbox is no problem,
parameter_bool.value = True
it comes kind of strange to retrieve the status. If I am not completely wrong then every parameter has two possibilities to achieve that: value, and valueAsText.
First I tried to check against the value:
if parameters[0].value is True:
then against valueAsText,
if paramaters[0].valueAsText == 'true':
It took me a bit to realize that valueAsText will return either 'true' or 'None'. Why does it not return 'false'?
However to check against it did not work. This part of the loop was never touched...
I ended up in using:
if parameters[0].value:
or
if not parameter[0].value:
Can somebody explain to me why it is impossible to check against the textual value by using the same strings that will be returned if I retrieve them this way?:
arcpy.AddMessage(str(parameters[0].valueAsText))
Wouldn't it be much easier to simply check the value against True/False?
In this link there is an enabled and altered property which returns a Boolean rather than the value property. perhaps those may be more useful
Hi Dan,
thanks for the link. I am using 'altered' for some string fields earlier in the tool to actually 'enable' the checkbox in the first place. I guess I can make use of 'altered' property, defining an initial value and switch that value forth and back when the checkbox is turned on and off (altered).
I am fine using parameters
I know that valueAsText returns 'true' or 'None' but I cannot check explicitly against these values, and I find that strange.