algorithmic modeling for Rhino
It just a for loop to add all the numbers.
I don't know python but the math / loop is the same anywhere. This is how it can be in c#:
private void RunScript(List<double> x, ref object A, ref object B)
{
double massAdd = x[0];
List<double> partialResults = new List<double>();
for(int i = 1; i < x.Count; i++)
{
massAdd = x[i] + massAdd;
double partialResult = massAdd - x[i];
partialResults.Add(partialResult);
}
partialResults.Add(massAdd);
A = massAdd;
B = partialResults;
}
Hi,
you can do this in c# with one line of code:
var massAdd;
massAdd = partialResults.Sum();
for the partial results you will need the loop. So take it for both as Michael Pryor said.
Yess this is exactly what I was looking for. But is it also possible with multiple list (number of lists are variable)? So that the results are also placed in different lists(see attachment). Maybe a loop that runs for each list? Or is it possible to input multiple lists into the Mass addition component?
Afraid, I don't quite follow. Do you mean writing a Grasshopper DataTree that holds multiple lists using GHPython? If so, have a look at this gist (there are also several threads on the forum related to reading/writing DataTrees using GHPython).
Yeah it's possible like Anders said. You just need to loop through your initial nested list and then use GH DataTree to get the result.
Nice example, careful with overriding the standard Python methods/classes/types though, can lead to some gnarly debugging down the road (in this case list):
Just because its funny...
private void RunScript(List<double> x, ref object A, ref object B, ref object C, ref object D)
{
double runningTotal = 0;
A = x.Select(i => new { i, totSum = runningTotal += i });
double runTot = 0;
B = x.Select(i => runTot += i);
C = x.Sum();
D = x.Count;
}
The For Loop will be probably faster, but this shows the use of LINQ.
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by