Two lists of differing lengths where each element in the list is another list, and a list of index values whose length matches the smaller list. I want to replace items in the longer list, with items in the smaller list based on the list of index values. I assumed List.ReplaceItemAtIndex would do the trick but no. Instead of replacing items in the longer list at the top level, it drills down to the sublists and replaces items there. The list at the end should be the same length as the original list not the length of the smaller list.
I can get close, I think, with Python, but I’m getting an out of index error (which makes sense… I just don’t know how to resolve it).
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
#The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN
original = UnwrapElement(IN[0])
collapsed = UnwrapElement(IN[1])
location = IN[2]
output = []
index = []
n=0
loc=0
for each in original:
if n == location[loc]:
output.append(collapsed[loc])
loc += 1
else:
output.append(original[n])
n += 1
#Assign your output to the OUT variable.
OUT = output
I read something about needing an imperative (sp?) operation but that’s beyond my skill set right now.
Does Imperative mean something like “do this once, then do it again using the results of the previous step as a new set of inputs”?
I have another challenge (more complicated) where I need to use the output of a series of actions as an input to the same series of actions over a series items in a series of lists. Is this a use of Imperative and can it be done with nodes rather than all in DS or Python?