Lacing on replacing item on index

hello, I am trying to replace a list of items at a list of indices into a list of elements. I am sure I am having problems with lacing, but i cant figure out what it is. Can anyone help me please? I originally had a list of 49 elements. I removed the 12 elements that I want to replace and then am trying to insert the new elements into those same places. Does that make sense? I tried the replace items at index but had the same lacing issues. Please advise.

Is there a reason you are not using the List.ReplaceItemAtIndex node, rather than removing the 12 items that you wanted to replace first?

Also, I don’t think this is a lacing issue, since your list is 37 items and 12 is less than 37.

What are you feeding into the “index” input on the Insert node?

1 Like

It’s not a lacing issue. It’s an index issue. You have 37 items but you have indices outside of that range.
What you really want is to replace the item at the specified index, but I’m guessing you ran into issues with that so tried this instead. I would suggest using Python if you’re trying to replace multiple items at multiple indices in the same list.

1 Like

I tried the replace items at index nodes already. Same issues. I am feeding the list of indicies into the index node. (you can see them in the “Flatten” node connected to the “Index” import above. :confused

Nick,

Yes, that is exactly what I am trying to do! unfortunately that I dont have any python skills. Are there any packages out there that can do this? it seems like it would be a fairly common issue. no? Thanks

@erfajo
Thanks, but what I am really trying to do is:
image

Clockwork has ReplaceItemAtIndex+ that does just this. Or you can look at this Python code that does the same thing.

dataEnteringNode = IN
list = IN[0]
elements = IN[1]
indices = IN[2]
count = 0
i = 0
out = []
for item in list:
	try:
		if count == indices[i]:
			out.append(elements[i])
			i = i+1
			count = count+1
		else:
			out.append(item)
			count = count+1		
	except:
		out.append(item)
		count = count+1

OUT = out
3 Likes

@Nick_Boyts
Jackpot! Thanks Nick!
image

Andreas actually uses a much nicer method for replacing items.

dataEnteringNode = IN
list = IN[0]
elements = IN[1]
indices = IN[2]

for e,i in zip(elements,indices):
	list[i]=e

OUT = list

The simplicity of Python still amazes me at times.

2 Likes

Its not working for me. Do I have to flatten all the lists going into these python scripts?

Those are both setup for one list of elements with one one list of replacements. You’d have to modify the code a bit to take multiple lists.

Seems to work for me with a simple test case.
image

yeah it did for me too. I just think its a flattening or a lacing issue

It’s hard to tell what the issue is when we can’t see any of your inputs. You might have more control using the node from Clockwork.

Gotcha.
But for replacing items you should be fine as long as your indices are within range.

Sorry,
Here you go its really hard with such a small screen:
image

He was initially trying to add items at an index but that was after he had already removed the same indices. What he was really looking for was a replace at index but it wasn’t working.

Yes you’ll need to flatten your list of rectangles. The list structure doesn’t match that of the indices (one index per element).

1 Like

Thanks!

It was a little confusing. I didn’t realize it until I looked at why his indices were out of range.