Getting a Custom Node to work with a list or single value

I created a custom node to check if a value is numeric, but it won’t work on a list. Only works on a single value.

What do I need to do to make this iterate over a list or process a single value?

Here’s how I’m attempting to use this. It just returns a single false value.

All ears for better ways to accomplish the overall problem…
We get a list of values that are typically numeric. This script finds the next number in the sequence. But, if someone has put letters in the designator, the String.ToNumber errors out and the script fails.
If the designator with a letter is filtered out (as I’m attempting to do here), but happens to be the last number in the sequence, then the script will pull the wrong next number in the sequence.
So, what really needs to happen is to remove the letters from the values and then remove duplicate numbers.
Any ideas?

501
502
503A
503B
504

Should become

501
502
503
504

So that the 505 can be generated.

The section after your input name (var[]..[]) is defining the input structure. In this case you’ve defined it as a multi-level list. If you’re wanting the node to work at any list level you you’d probably be better off without defining the structure.

1 Like

I removed the structure definition, but it’s still doing the same thing. Just a single value for the whole list instead of a value for each list item. :-/

You’re not creating any sort of loop for your lists. An Imperative statement isn’t necessary and it would be easier to just use a conditional statement anyway, so I’d suggest doing that. You don’t even need a custom node at all, just a code block would be better suited.

Also keep in mind, if these are string values then none of them will be divisible by 1. What you’re really looking for are the string values that can be converted to numbers. So check for that instead.

2 Likes

Excellent. This solves the initial issue.

Any idea how to keep the numbers resolved as false by stripping the letters out of it?

Here’s what I have right now, but it depends on the String.ToNumber node having an error. It works, but I’m not sure I should use that route.

Use a conditional statement like the code block I suggested to prevent the warning (this also allows you to skip the conversion). Then filter for the numeric values and concatenate back into a string.

1 Like

That did it! Thanks, Nick!

1 Like