-
Notifications
You must be signed in to change notification settings - Fork 1
/
boolean_transform_node.py
40 lines (34 loc) · 1.33 KB
/
boolean_transform_node.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
class BooleanTransformNode:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"input_string": ("STRING", {
"multiline": False,
"default": "0.0"
})
}
}
# Returning both INT and BOOLEAN outputs
RETURN_TYPES = ("INT", "BOOLEAN")
FUNCTION = "transform_to_boolean"
CATEGORY = "CRT" # Category for UI organization
def transform_to_boolean(self, input_string):
# If input_string is a list, get the first element
if isinstance(input_string, list) and input_string:
input_string = input_string[0]
# Ensure the input is a string
if not isinstance(input_string, str):
input_string = str(input_string)
try:
# Convert the string to a float
num = float(input_string)
except ValueError:
# If conversion fails, treat it as 0
num = 0.0
# Boolean value (True if non-zero, False if zero)
boolean_value = num != 0
# Integer equivalent (1 if non-zero, 0 if zero)
int_value = 1 if boolean_value else 0
# Return both int and boolean values (int_value and boolean_value)
return (int_value, boolean_value)