I’ve read a lot of similar questions but cannot find one to help solve lists with the amount of layers I have.
In this example, I want to replace a lists on blank strings with actual values at a nominated index:
I’ve tried various combinations of levels/lacing, and changing list structure of the index input, but cannot get the result.
Would be ideal for an OOTB or python method.
Thanks in advance.
dynamo graph (updated with desired result codeblock)
replaceitemindex_test.dyn (27.7 KB)
replaceitemindex_test simple.dyn (10.7 KB)
It’s still a little confusing trying to understand what you’re really after, however, I think your issue is with
ReplaceItemAtIndex (assuming it’s the OOTB node). That node replaces a singular index from a singular list. Meaning it won’t replace multiple items from the same list at the same time. You would need a custom node (archi-lab has one) or python to get what I believe you’re after.
Apologies for the confusion, I’ve updated the original post to show codeblock of what I am trying to achieve. Hopefully that makes more sense.
I have tried the archilab & clockwork nodes. Still couldn’t get what I wanted, plus they both gave different results.
I guess I will hope someone has a python method or direction on level/lacing for custom node.
If not, I’ll have to think of another way (avoid using the replaceitematindex node) to compile the list.
A more simple example might be helpful. It’s hard to follow when we can’t see the entire list at once. A simpler example is also a good way to prove the process works before introducing additional items or list structures.
Agreed. I have updated the OP with a much simpler example.
Felt like I got closer too but couldn’t get the last bit.
@AB01 Try this:replaceitemindex_AS.dyn (21.7 KB)
for oriSeq,redInd,repSeq in zip(IN,IN,IN):
for x in redInd:
oriSeq[x] = repSeq[x]
OUT = IN
@AmolShah Brilliant. That works well. Thanks.
Another thing, I have situations where the sublists are replaced in the middle of the “parent” layer only.
Can your python script be modified to handle that? See below:
replaceitemindex_test_middle.dyn (38.6 KB)
@AB01 Yup, that should be easy.
replaceitemindex_test_middle_AS.dyn (39.5 KB)
for oriSeq,repInd,repSeq in zip(IN,IN,IN):
for i,x in enumerate(repInd):
oriSeq[x] = repSeq[i]
OUT = IN
Thanks so much for the solution.
And thanks Nick too.