Check for checkbox status

1396
2
10-11-2014 07:28 AM
TomGeo
by
Occasional Contributor III

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?

- We are living in the 21st century.
GIS moved on and nobody needs a format consisting out of at least three files! No, nobody needs shapefiles, not even for the sake of an exchange format. Folks, use GeoPackage to exchange data with other GIS!
0 Kudos
2 Replies
DanPatterson_Retired
MVP Emeritus

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

0 Kudos
TomGeo
by
Occasional Contributor III

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.value. However, I do not know what the value actually is.

I know that valueAsText returns 'true' or 'None' but I cannot check explicitly against these values, and I find that strange.

- We are living in the 21st century.
GIS moved on and nobody needs a format consisting out of at least three files! No, nobody needs shapefiles, not even for the sake of an exchange format. Folks, use GeoPackage to exchange data with other GIS!
0 Kudos