Mapping in list of sublists to another list


#1

Hi

I have what I think is a fairly simple question. I have a list with sublists, and each sublists can be of any length. I also have another list with variables the same length as the first list, only without any sublists. Each sublist I want to send to a function together with the corresponding variable in the second list, and to something to all variables in the sublist. I can do it with some simple python scripting, but I was wondering how I can do it without it. Just with Dynamo nodes. Can anybody help me with this? Below there is an example definition…

Thanks!

Thomas

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Code in Python-node:

a = IN[0]
b = IN[1]

i = 0

while i < len(a):
j = 0
while j < len(a[i]):
a[i][j] += b[i]
j += 1
i += 1

#Assign your output to the OUT variable
OUT = a


#2

(Sorry about the formatting in the post… There seems to be some bugs in the text editor…)


#3

Hello Thomas,

this looks like a regression, because it should work very easily in Dynamo - like this:

batchadding1

Doing it like this used to be possible in Dynamo 0.6.3:

batchadding2

for the time being, if you really want to do it without Python you could do it like this (count the items in each sublist and repeat the items in the second list accordingly so you end up with two list of identical structure):

batchadding3

I would suggest you file a bug on the Github site (https://github.com/DynamoDS/Dynamo/issues).

EDIT - Never mind that. I am filing the bug myself because this could be important for the impending 0.7.4 release.


#4

Hi

Thank you very much for your quick reply. I learned some more about mapping lists in Dynamo. I´m previously used to Grasshopper, and the move to Dynamo isn´t always that direct.

However, I want to use this with a custom node that overrides graphics in the active view, and this exact strategy doesn´t seems to work in that example. I attach a screenshot of the definition below. I should probably have provided that definition from the beginning.

My idea is to try to let the Dynamo handle the list mapping as much as possible, and try not to do that inside python nodes or custom nodes. I believe the custom nodes will be more flexible that way when you don’t need to change code for different list and sublist scenarios. Of course, it could be I´m doing something wrong in the custom nodes as well.

The final custom node takes one element and one color and changes the color of that element in the active view in Revit.

Thomas


#5

Thomas, the screenshot you posted isn’t really very helpful.

Could you zoom into your graph until you can see all the label texts and then click on the screenshot button in the top right corner? Unfortunately, it’s a long-standing bug in Dynamo that the screenshot quality is related to the current zoom factor in canvas… :frowning:

BTW: if the screenshot doesn’t show your entire graph, you may have to move the elements on canvas - another annoying (and rather old) bug.


#6

Oh, that screenshots wasn´t very good. Here is a new one:


#7

List.Combine

You may try List.Combine:

 

 


#8

Oops, should have thought of that myself, Ku Ye. Nice. Thank you.

Thomas, I would assume that the problem in your graph is related to the nested list structure. Most (if not all) of the Python based nodes that access the Revit API (like the one you’re using to override colour) will only work with flat lists. So without having tried it on this particular example, my guess is that you will need to flatten both lists (grids and colours) before connecting them to the inputs of the custom node.


#9

Thanks Yu and Andreas! Works perfectly with list.combine. But I had to flatten the lists, like you said Andreas.


#10

I really would like to us the combine node for two list of points. I do not seem to be able to find the right combinator for this operation. Any thoughts?

 

cca