Replace an item at multiple indices

Hi all, apologies if I chose the incorrect category.

I am trying to replace one item at multiple indices within a list and can’t seem to properly use levels and/or build my graph accordingly.

All it does now is replace the item on the first index (44) and not the rest. Any thoughts?

Hi @s.proch and welcome…looks like you use clockwork and thats great for multiple replacement, its difficult to say which kind of level and lacing you need without see what you input…but its for sure play around with lacing and list level…

Thank you!
Here are my inputs, hope they are clear to read

Hi seems when you only have one replacement on multiple indicies it cant handle…try something here or try genius loci replacement node probably it can handle it…

Seems like this could work for me. Thank you!
Where do I find this node that you talk about?

1 Like

Havent tried, i think about geniusloci, insert at index…

arhhh sorry that node will not replace only insert…

No worries! The method you mentioned above works perfectly for me, thank you!

Now… do you think of any simple way to cycle/repeat this process for every item from the code block in the red circle? I guess I could just copy those couple of nodes 32 times to achieve this, but I don’t think that’s the most efficient way.

What I am trying to achieve is to replace my autocad layer names with corresponding block names to be inserted in my model. Hope it makes sense.

You could join them or a list create if i understand right :wink:

I will try. Thank you!

great, let us know when it works;) good luck

Amigo @s.proch Buenas. I have also had a very bad experience with Replace at index, so far I have no idea how it works, in the end I ended up using an If, as long as you have both lists with the same number of Items you can create a list with Interspaced Items as you wish, if it is just replacing plain text maybe String.Replace will also help you, I hope it helps!

1 Like

A dictionary might be better for direct replacement as it will be faster and easier to build up.

1 Like

Hi all! Thank you for the suggestions. I don’t think Dictionaries will be of help, or at least I have no clue how to use them in this case, I am fairly new to Dynamo.
I have meanwhile got to this point. I have list of lists containing the indices and also list of lists containing appropriate numbers of replacements.
I can’t seem to make the replace node set up correctly. It seems to be working almost as I need it to. However, it puts the replacements into a sublist, creating 32 sublists (same as the number of replacements) each containing the original values and the replaced item at specific indices. Could this be done in a single list?
I hope it is clear what I am trying to achieve here. Please see the screenshot, it is all replaced correctly but on separate lists :frowning:

This is an example of using a dictionary to get the desired values: Can i make this ReplacebyCondition, StringContains script smaller? - #8 by solamour
And another example from today: Lookup Value equivalent in Dynamo? - #5 by christian.stan

1 Like

Much appreciated! I will give it a go.

1 Like

I haven’t tried dictionaries yet but I did realise that the only thing I needed to do was list.flatten both lists to then properly replace the items.

1 Like

Anyone know why the OOTB nodes don’t work? I never understood why I should have to use archilab or Clockwork nodes to accomplish this “simple” list operation.

“Simple” is in quotes, because I can’t write code :frowning:

They do, but they are designed to replace one index at a time, and aren’t built for bulk replacement.

How are they not working for you?

1 Like

As you describe, they do not work for bulk replacement.