Flatten list after project input onto node not working

hello, I am trying to flatten a list into sublists that mirrors the original list structure from which I extracted the location of the points. If I use the Flatten(lst<1>) code block it works great if I have more than one sublist in my list, but if I only have one sublist, it falls flat and fails flat. I need the list structure after the project onto node to match the original list structure no matter what. What am I doing wrong? Thanks!


Try using list @ level 2 instead.

You mean like this?
It doesnt seem to work?

That isn’t how you call list levels in design script. In this case I think it’s best to teach you to fish here instead of providing the answer directly as it’ll help you in quite a few of your graphs, so give this a shot:

  1. Place the Flatten node instead of writing it in a code block.

  2. Set the level in the node to Level 2 with shortest lacing. Make sure the node preview is structured the way you want for both a single depth list and a nested list prior to proceeding.

  3. Highlight the node, right click somewhere in the background, and chose ‘node to code.’

  4. Edit variable names as desired.

  5. Come back and post the solution so others can also learn, or post where it failed and I’ll help you out.

1 Like

yeah I tried this one, the problem is that the points need to be flattened from the bottom up, not the top down. the structure at the bottom of the screen is correct. But when I run only a single element through the script it screws up. please advise.
image

The issue isn’t Flatten - it’s that your FilterByBoolMask nodes don’t return the same list structure. It’s probably something happening before all this that is causing the problem.

1 Like

Thanks, bu I succeeded by chopping the list at L3 this gave me the structure I needed either by a single element or multiple elements selected.
image
image

I would strongly recommend you figure out what’s causing the problem and fix it rather than just provide a band-aid solution. It will help you learn and hopefully prevent you from running into a similar problem later on. I would also suggest using list levels over lacing when possible as you have much more control over how things turn out with list levels. In fact, Flatten @L3 gives you the result you’re looking for without chopping your list and then flattening with longest lacing. Learning to understand your mistakes is what makes you better, not finding a way to cover them up.

4 Likes

I’m pretty sure putting a list throught List.Join in a Code Block can make that happen.

Hi @Nick_Boyts as far as I can tell there is no way around this problem, this is occurring at practically the beginning of the list. The problem is the user selecting can change from one item or many, and each item may have anywhere from 0-10 items in the list. the problem is that when the initial selection is only one item, the original list on the left gets flattened out when compared to the list of lists you get when you have multiple items selected. I was trying to normalize the list structure at this point so that the rest of the script further down the line would work when only one item was selected by the user. Both of our solutions achieved the result I was after, but I changed my script to use Flatten @L3 since you seem to think its better. Please forgive me by trying to “cover it up” but all I know is all I know and I can only use that to try to find the solution. I come here to this forum to help me learn from outstanding individuals such as yourself, but there is no way I would have discovered that one on my own. As much as Ive read about list levels, I still find them unintuitive and difficult to use. I am getting better with them but its a slow process so please forgive me and be patient. If you have a dynamo class or know of one that would help me please dont hesitate to let me know about it, as I am thirsting for one.
@PauLtus
can you show how you would put a list through a List.Join in a code block please? the Design syntax section in the dynamo primer is exceedingly limited. Also, why would you have to put it in a code block? why cant you just use the list.join node?

As always gentlemen, I greatly appreciate all your help I cant do it without the help of this site!

Sometimes you just have to make it work. I get that. It’s just hard to see what is going on in the rest of your graph. One option you can try would be to create a list from your selection the flatten it. Flatten will still keep a single item in a list so your list structure should be the same for single selections and multiple selections.
image

1 Like

@mix See if this works…

@Vikram_Subbaiah
Yes that does work. That is the same thing @Nick_Boyts Suggested. I am using that method now. you method illustrates my dilemma the best though. So I will select it as the solution. :slight_smile:

1 Like

You already have a solution but just to answer your question:


Although I think I understand why this happens I can’t really properly explain it with words, it does have something to do with the way you input things in the node or code.