Combine List with different Index Number

Hello everyone
I’m relatively new to Dynamo.
I’ve been working with Civil (Civil 3D 2023) for a while now, and now I have time to get involved with Dynamo. With the help of the forum, I have already successfully created smaller scripts.
Although it is always a bit difficult as my English is not so good and I am not a programmer either. But it works out quite well and I learn little by little.

Now I’m working on a new test script and failing at a task.

I have 2 lists with different numbers of results.
In the first list I have Null values.
I would like to replace Null with the results of the second list.
the null values of List 1 do not have the same index as the results of List 2.

Does anyone have a solution for me?

Thanks in advance for your help. :slight_smile:

Can you explain where these lists are coming from and what the indices relate to? It would be much better if you could keep the same structure and length for both lists so that you have a 1-to-1 relationship. Even if you can ensure you have the same number of nulls and replacement values every time, it’s no longer trivial to map the right value to the right index - you have to use custom nodes for replacing multiple indices or switch to python. Keeping the correct structure is always a better option when possible.

I have a test DWG with 4 points with coordinates (X,Y) and read the height (Z) from the DGM.
That is the height 73 in the first List.

Additionally I have MTexts (Content Z) near the points.
Using a search radius, I query which points are nearby and what the content of the text is.
That ist the height in the second list.
There are not always the same number of texts as points.
Now I want to replace the Z-height in the first list with the Z-height in the second list.
I know that it has to go to the positions of zero values. I determined this through another loop.
just how do I replace it?

I can post the working part tomorrow.
But I need to clean up and remove the wrong knots first.

How do you know that the first replacement value goes with the first null and the second replacement value goes with the second null?

Hola amiga @Melanie_Germany buenas como estas? :cowboy_hat_face:
this is the kind of cases where is much better use a for bucle, may be some one can guide you making a code block or a phyton script, a bucle for will works but is much more work using nodes!

Thank you for your help.
You put me on the right track with your question.
Dynamo didn’t know what to replace, of course.
I have taken a different path and am now reaching my goal.

Thanks for your help. I solved it in a similar way.
Yes, it is indeed time-consuming with knots. But unfortunately I don’t know Python and so I can at least create it myself without the support of a programmer

Hi. You could also use the List.ReplaceItemAtIndex+ node from the Clockwork package. It allows you to replace multiple items at multiple indices. You will have to be careful with list levels if you were to go into more complicated lists.

Thanks, I saw the node from Clockwork.
However, nothing really solves my problem in any way.
Nick_Boyts was right that I don’t know the correct position of the value to be replaced.
I didn’t solve this problem with my new way either.

Since I absolutely can’t get any further, I’ll post the script and the DWG here.
Maybe someone has an idea.

I know it’s a little messy.
So here are the 2 positions that interest me as a picture.

Test.dyn (515.1 KB)
Test.dwg (7.7 MB)


You need to show your full graph and all the node previews for us to understand what’s actually going on, but the problem is you’re losing list structure in at least one place.


You have a list of true or false values but you reduce it to a single list of nulls (losing the structure) and then add it to another list and flatten (ignoring list structure). I have no idea what those values represent or where they’re coming from but you can’t just ignore the list structure, combine unrelated lists, and then expect your values to line up at the end.

Hola de nuevo amigos buenas. :cowboy_hat_face: amiga @Melanie_Germany guten tag, doing this in dynamo using only nodes is something that has always blown my mind :exploding_head: I always forget the necessary conditions to make it work, the if node well configured does the magic but it needs the following conditions:

  1. All the lists must have the same size.
  2. All the lists must work at the same level (the simplest is always flatten lists).
  3. The number of items to be replaced must be equal to the number of replacement items.
    The difficult part is to create the list of replacement items in the correct order, i let you an example.

    Amigo @Nick_Boyts do this with indeces has always seemed difficult to me, the List.GetItemAtIndex node I like very much because it works very well and it is very useful, don’t you think that the node: List.SetItemAtIndex should exist ? I have never been able to make work the nodes Insert, ReplaceAtIndex or ReplaceByCondition without altering the original list and deliver it as is by just replacing the values in the appropriate indices, what do you think??

How do you know that the first replacement value has to go with the first two indices in the original list? This only works if you have one null value for each coupling of values/nulls in the original list. Is this always the case?

ReplaceItemAtIndex is functionally the same as a SetItemAtIndex node. The only limitation is that you can only replace one index at a time. To replace/set multiple indices within the same list at once, you need to use a custom node or python.

Yeha you got me, after a couple months or a year may be i don’t remember my own improvisations, srry about that; this is the good one: the idea is to repeat the replacement items the same amount of times as the difference between the indices of each “null”, so we get a list of the same size (or almost) as the original and there is always a suitable value when we find a “null” or “Empty” or whatever value we need to replace in the list of conditions, it’s a functional improvisation and I don’t think it’s free of fail, but it hasn’t failed me, in the end it’s just an alternative, because I always run into the limitation of ReplaceItemAtIndex that you mention, and ReplaceByCondition only works well for 1 single value and not a list!


Any way if some one want use this alternative check twice the out come before use it in production plans or considere use phyton instead!!