List.ReplaceItemAtIndex - multiple indexes

Hello everybody,

I didn’t find any solution in the forum so i create a new topic for this question.

I have a list of lists and would like to replace items at specifics index of the sublist but i’m not getting any results with the node list.ReplaceItemAtIndex, as you’ll see below, the index 16 of my sublist is modify but not the index 18,20, 22 etc…

Did you try Lacing > Longest

Yes i did, it’s not working as well :

There are multiple threads already on the forum discussing this. You’ll need to use a custom node or python.

Consider a few additional steps following List.ReplaceItemAtIndex


replaceMultiple.dyn (13.2 KB)

3 Likes

The Clockwork package has a good node for this too. It works the same as the build in node, but works for multiple indices.

2 Likes

hello is possible to use a list for the input “item” at List.ReplaceItemAtIndex node? I Do not find a way to replace for the index x, the item x of the input list.

Something like this?

ind1 = 0..List.Count(lst0)-1;
ind2 = List.SetDifference(ind1,ind0);
ind3 = List.Flatten([ind2,ind0],-1);
bln1 = List.Contains(ind0,ind1<1>);
lst1 = List.FilterByBoolMask(lst0,bln1);
lst2 = List.Flatten([lst1["out"],rep0],-1);
lst3 = List.SortByKey(lst2,ind3)["sortedList"];
4 Likes

Amazing, I have learnt something useful new today. I got warning error with designscript code, but working perfect if I use the node sort by key at the end. Here a test with one script I got. Thanks

1 Like

[quote=“Vikram_Subbaiah, post:8, topic:53144”]

ind1 = 0..List.Count(lst0)-1;
ind2 = List.SetDifference(ind1,ind0);
ind3 = List.Flatten([ind2,ind0],-1);
bln1 = List.Contains(ind0,ind1<1>);
lst1 = List.FilterByBoolMask(lst0,bln1);
lst2 = List.Flatten([lst1["out"],rep0],-1);
lst3 = List.SortByKey(lst2,ind3)["sortedList"];

With this Python code it can be done as well, although for this I prefer OOTB nodes.

_list = IN[0]
rValues = IN[1]
iValues = IN[2]
if len(iValues) > 1 and len(rValues) == 1:
rValues = [rValues[0]] * len(iValues)
if len(iValues) > 0:
for (index, value) in zip(iValues, rValues):
_list[index] = value
OUT = _list