I have a list of YES/NO text and I would like to convert these to their boolean representation. I first convert the YES entries in my list to true and dynamo does this just fine as shown below. However, I do not understand why the last ReplaceByCondition node returns the same list from the prvious step.
Also, are the true entries in the first ReplaceByCondition node truly boolean values? I ask this because I modified my graph to use the != node and this was my result.
What are you unsure of? The result is correct. You want to replace anything that doesn’t equal true with false and it only changes the results that weren’t already true.
The (purple) true and false objects are actual booleans as you can see here:
@Andaroo try running your list through a String.TrimTrailingWhitespace node before passing it through your ReplaceByCondition node… It’s possible the “NO” has an extra space or two after it, but unlikely if @Ewan_Opie’s code block worked
If I change the condition to use non-booleans it works. I’m guessing the node is getting confused because it’s checking the condition but the input item is already a true boolean so it uses the replacement value anyway.
I’m seeing the same thing on my end @Nick_Boyts - oddly I can’t even replicate @Andaroo 's != true outcome either; only the CodeBlock method returns correctly.
I can’t replicate it either. CodeBlock only seems to work if both conditions are run in the same line. Breaking the conditions out into separate checks gives the same incorrect output.
EDIT:
Order matters, but item value vs conditional value doesn’t. Any true value seems to break the function.
I have found that Dynamo generally hates performing analysis on mixed data types. By converting only some of the data to a Boolean (true/false) you create this mixed data set. This is similar to when a dataset contains null values or an empty list. Sometimes I have been able to get around this with lacing and level manipulation, but that is dicey to say the least. As @Dimitar_Venkov pointed out, simplifying your code to perform the function on the data while it is a single type is certainly the simplest method here.
Another good test here is to ensure the correct data is being fed in before you proceed. Run the data into a List.UniqueItems node and then into a few other tests or List removal functions to produce a single Boolean for ‘all data is matching types’. That Boolean can then cause Dynamo to throw up a popup to say something like ‘The given dataset has unsupported values. Please review the dataset and try again.’
@Nick_Boyts@awilliams@Andaroo it is worth noting that there are certain type conversion rules that are built in to the language in Dynamo. When strings are converted into boolean values, the following rules apply:
An empty string is equivalent to a Boolean ‘false’
A non-empty string is equivalent to a Boolean ‘true’