Get item at index with slider for always different list length

When creating Generative Design graphs I constantly run into the below problem. This problem would go away if sliders had inputs but because they don’t I need a way to use a slider to “select” a single list item but the problem is that the list will be different for ever project or in some cases different for different data selections within the graph itself. The best solution I can come up with is below, however it results in the slider having duplicate “selections” which would be wasteful of memory when actually running this in Generative Design. The red circled list is the one that changes its list length and therefore needs a dynamic solution.

Am I missing something? How does everyone else deal with this?

Thanks,

@SteveDFT

-1 :wink:


1,2,3,4  # 🎡 count

0,1,2,3,4 #  🏒 Index

when i would speak only python

Before you send a graph to GD you need to configure it. This means users will need to open the graph in Dynamo and set up the min and max value for their sliders. This is THE way to have the most effective use of the tool.

Alternatively you can us a % value - set the slider to vary from 0 to 1, with a small enough step to hit every your ‘worst case’ scenario. Multiply that decimal value by the count, and round the value off using a Math.Floor. In design script that looks like this: lst[Math.Floor(List.Count(lst)*selectionParameter)];. That will return the item in the list at the ‘percent’ at which the parameter value is set; not it can be hard to get the ‘last’ item this way as only a value of 1 will get that, so you may want to limit your slider to just before 1 (say 0.99 if you’re stepping by 0.1) and append an extra item to the end of the list.

Often I have found that when this comes up there is an alternative way to achieve the exploration that scales to users better, but we need to see the larger context to know what that is.

I typically try to use the “percentage” option that Jacob suggested because it tends to be the most flexible without impacting runtime too much, but that requires your lists to still be relatively similar in length and also has issues with the extreme values as he mentioned.

An alternative (if the order of the input values doesn’t matter), is to duplicate your input list multiple times and shuffle the results to create a random list of a given length (100, 1000, etc.). You can then use static slider values to select a random input. This of course can introduce some bias if your final list doesn’t contain an equal number of each input, but avoids the issue with the min and max value being less likely. You just need to make sure the list is long enough to make the bias negligible.

Both of these options have pros and cons, so it’s good to try them both and see what works best for you.

Thanks all for the suggestions. I will give these alternatives a try.

1 Like