Custom Node will not accept empty list

I have a custom node that throws an error if there are multiple empty lists for one of the inputs. If there is only one empty list, it does not through an error. If I pull the python script out of the custom node and run it that way, there are no errors. Any suggestions?

Multiple empty lists

Single empty list

Custom node

My current work around is to replace empty lists with and empty string, but I would prefer to avoid that.

Because it cannot undertand you are feeding strings, empty strings since there are nothing.
If you look, your input IN[2] is explicit as string[.]…[.] so it will not run with var[.]…[.] (that’s what it saying on yellow popup).
Try only to change the input block with var instead of string

I thought I had this working, but I was wrong. As a test, I created a simple custom node.

Here are the results. It will accept a single empty list, but not multiple.

@ashish.ganta @Aparajit_Pratap thoughts?

what version of Dynamo is this?


Looing into this.

1 Like

it is correct, because:
[] is ONE LIST
[][] is LIST OF LIST
[]..[] is arbitrary rank of list.

So you don’t have to specify var or it will look only for a list. Try with arbitrary rank

1 Like

@keith.sowinski to answer your second question with the simple “Test” custom node, @FabioDeAgostini is right in his explanation. Another way to simulate the custom node is by defining a DesignScript function in a code block node like below:

You’ll notice that when I change the input parameter type for the function “foo” from var[] to var[]..[] it works. This is equivalent to changing your input node in a custom node definition:
from var[] to var[]..[]. []..[] basically means a list of arbitrary rank or dimension as @FabioDeAgostini explains.

Thank you @Aparajit_Pratap @FabioDeAgostini.
I have been using var[] just to make sure inputs always take the form of a first order list. It sounds like the better practice is to avoid using var[] and restructure the input within the custom node. Unless you know for sure the input will never contain empty lists. Do you agree?

Don’t do this…

Do this instead…

@keith.sowinski @FabioDeAgostini I stand corrected. The intention is not to prevent or discourage (custom) node authors to avoid using input types of a certain rank. Empty lists should not be treated any differently than non-empty lists and should be consistent in their replication behavior. The fact that a custom node or function defined in a code block node returns null for an empty list is in fact a regression from a previous version of Dynamo and we will prioritize a fix for this. The best way to explain what I mean is by way of an example from the older version of Dynamo (2.1.x), in which it worked as expected:

As you can see the above result is what you should expect. Notice that both the empty and non-empty list return the same structure for the output irrespective of whether they’re empty or not. In other words since the input type is a list of single dimension and we are passing in a list of a higher dimension (2 in this case), the function foo replicates over the input to produce 2 items instead of 1. If on the other hand you were to pass a list of single dimension, you would get the single list returned from the function.

To summarize, what you’re trying to do by using var[] for your inputs is correct, if that’s what you intend for your custom node; just remember that it will not replicate for a list of rank 1 and will replicate for a higher dimension list. Also note that if you pass an input with a single value, since your function accepts an input of var[] the single value will get promoted to a list, which is why you see the single Polyline object returned inside a list of a single item in your example above. Thanks for pointing out the bug!