Grasshopper

algorithmic modeling for Rhino

duplicate the component "Shortest List" into a custom component

Hi all, 

Since two weeks I'm trying to design some custom component for grasshopper. To do it I use C# and Visual Studio.

I have almost finish my last component but I need your help to finish it. 

One of my outputs is not exactely what I want. If I was using only grasshopper's components, I would use "Shortest List" to solve this probleme. So I want to "copy" this fonction into my component. 

My output should be : 

but currently is : 

I think that this list take the same "shape" as an other output of my component. So I have to use "shortest list". 

I hope that my request is clear. Don't hesitate to ask for details ! 


Thanks a lot, 

Mathis

Views: 472

Replies to This Discussion

It depends on whether you want to create new lists that match, or whether you're happy just creating a single loop that acts like Shortest List.

For looping:

int shortest = int.MaxValue;

shortest = Math.Min(shortest, List1.Count);

shortest = Math.Min(shortest, List2.Count);

shortest = Math.Min(shortest, List3.Count);

// ... etc. etc. with all your lists.

for (int i = 0; i < shortest; i++)

{

  var value1 = List1[i];

  var value2 = List2[i];

  var value3 = List[3];

  // ... etc.

}

Actually creating modified lists will also involve first finding the shortest one, and then using something like RemoveRange() to cut all lists down to size.

I am interested in this "Remove Range" fonction. 


I tried to do it but I think that I made something wrong. 

To use this fonction it's something like : List.RemoveRange("start_index", "number of object to remove");

isn't it ? 


 

Like David said but I just made new lists rather than cutting the lists with RemoveRange()

private void RunScript(List<double> x, List<double> y, List<double> z, ref object A, ref object B, ref object C)
{
List<double> xShort = new List<double>();
List<double> yShort = new List<double>();
List<double> zShort = new List<double>();


int shortestList = Math.Min(x.Count, Math.Min(y.Count, z.Count));

for (int i = 0; i < shortestList; i++)
{
xShort.Add(x[i]);
yShort.Add(y[i]);
zShort.Add(z[i]);
}

A = xShort;
B = yShort;
C = zShort;

}

Attachments:

ok thank you very much ! 

RSS

About

Translate

Search

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service