Updating values in a list

I have two lists being the first with sublists with 4 items (Walls) and second with sublists with 2 items (OpeningAreas), as shown in the attached figure.

In both lists I have the first item of each sublist the ID of a wall.

How do I do a looping that ACUMULATES the sum of the values contained in the 2nd element of each sublist of the “OpeningAreas” list in the 4th element of the sublist “Walls”?

But, this sum can only occur if the first item of each sublist is equal, that is, it can only add up if the ids of the walls are equal.

Suggestions ??

Try nodes such as List.Deconstruct, ==, If and Sum for a start. You will find all related descriptions in the Dictionary

List.Deconstruct accepts only one list for input.

Is there a node that substitutes a item in the list?

I want use the first element on each sublist in the list “OpeningAreas” to serarching for the same element on each sublist in the list “Walls”.

So, when I found it, I need substitute the 4th element on the sublist in the list “Walls” by the value in 2nd element on the sublist in the list “OpeningAreas”.

I don’t want use Sum node because the values on 2nd element on the sublist in the list “OpeningAreas” is already sumarized.

Try to play with the lacing.
A screenshot of your updated graph would be useful.

Join the lists together into one list with a List.Join node.

List.getItemAtIndex and List.RemoveItemAtIndex to get the Element Id out of the list. Lacing will matter here.

List.GroupByKey to group the lists of areas (which no longer contain the Element Id) by the Element Id which is the key.

Math.Sum can then be used to total the values (lacing again). You can then use a List.AddItemToFront to place the Element Id (the unique keys output) back into the list.

I’m almost able to do what I want.

I’ve used the “List.ReplaceItemAtIndex” node. But, it’s only working for one item, as shown in the figure below.

You can try playing with list@level this time (on the index input of List.ReplaceItemAtIndex, for instance).

I tried to use list @ level in the suggested location of the graph but, I did not understand how it would work in this case. What I noticed is that Dynamo only looped once on the Walls list. Any other suggestions?

You’re right, I answered too quickly, the level would probably be needed on the list input (but I can’t test it right now, if you post your dyn, someone will surely take a look).

This my complete graph. I’ve grouped the nodes into the magenta box.

ServiçoAlvenaria-R03.dyn (65.9 KB)

Try the List.ReplaceItemAtIndex+ node from #clockwork it should do multiple indices :grinning:

I think this problem is not on ReplaceItemAtIndex node, but on the nodes before it. :frowning:

The reason that it is working for that instance is because it is the only instance in the list where the == is producing a true output. This is because you are comparing the lists as if their sublists are aligning, aka Walls Sublist 0 Item 0 == OpeningAreas Sublist 0 Item 0, and so on. If you change the == node’s lacing to cross product you will see the occurrences of “true” will be appearing on the indices where the Walls Sublist X Item 0 == OpeningAreas Sublist Y Item 0, but the cross product output of the == node will not work with the If node, but will show how your Walls list would be reordered to align with the OpeningAreas list.

Alternatively, you could get your wall data in the order of your openings data by removing the Walls > Collect By Category in your green and orange groups, and instead collecting the Wall Elements from the Element.GetParameterValueByName output of your graph where you collected the openings’ host elements like this:

This would result in your Walls lists being constructed in the order of the OpeningAreas orders, so that the == and If nodes correctly replace the list items (worked on the model I tested it on)


An example of retrieving sublist items based on reference list input values contained within the sublist.
From your initial post, I assume this is the workflow you are requiring?

1 Like

Great, @awilliams!!

I simply ordered the “Walls” and “OpeningAreas” lists and solved my problem.

When you explained to me about the order of the elements, I realized that ordination was the key to resolving the issue.

I am sharing the part of the graph that I posted before with the final solution.

Thank you very much!!

1 Like