List.Map with List.UniqueItems translated into Code Block

Hi everyone!
There was a topic some time before about using List.Map function in Code Block. I wonder, is it possible to translate some function, for instance List.UniqueItems, into DS syntax to use it with “__Map” function directly in one Code Block instead of connecting node with function?

1 Like

If you want to get everything into a code block I would write a simple DS for loop then call the function within the statement. Seems self defeating to call the List.Map node in DS given its purpose is ultimately to iterate lists within the visual programming environment (i.e for those not looking to code)

Thank you very much. It seems that my task is solved. Here are some results. I had a list of sublists with numeric values and I wanted to have only unique values in each of sublists. Instead of using method “A”, i wanted to do everything in Code Block, so with the help of your answer i’ve created methods “B” and “C” and it seems that they work fine. May be someone knows any other method of completing this task? It would be interesting to get to know…

Hi @architect.bim
Your definition is perfectly fine. I would just like to suggest a different approach using replication guides…

1 Like

Hi! Thanks much! It is an interesting solution too! And what does “DSCore” mean? It seems, that this function works fine even without “DSCore”.

Design Script Core

I understand this. But what is the reason for writing it before the “List.UniqueItems” function?

It is to call the function from DS.

And what is the difference between calling this function with and without “DS Core”?

The results seem to be the same.

Sometimes what happens when you call anything in code block it gets conflict with custom packages. So to be sure we call it using DSCore. Does that make Sense!

1 Like

Sure, that makes sence. Thanks much!

1 Like

Hello!

I’m trying to tackle the same problem.

I need a variaton on the list.map function, that can apply any function to a list. The reason for this is so that I can use a custom node to apply multiple functions to list[0], then repeat those functions for list[1], and so on.

In this example i’m trying to generate multiple .rvt roof models using global paramters for depth, width and angle. Each combination given should save a RVT file based on the input, then move on to the next index in the list.

def TestLoop2(var1:var[]..[],func1:Function){

c = [Imperative]{

Succes = {};

	for(x in var1){
		Succes[x] = __Apply(func1, x);

	}
	return Succes;
}
return = c;

};

image

Hope you can help! @Kulkul @Thomas_Mahon

For anyone searching for the same kind of method, here is a solution:

This DesignScript is able to loop while using Dynamo-Nodes within that loop!


image

#loop #designscript #revit #looping #forloop

1 Like