Grasshopper

algorithmic modeling for Rhino

Hi,

How can I write a code C# to duplicate items?

I found this line of code that returns 10 items of integer 1.

var integers = Enumerable.Repeat(1, 10);


How to write something like this, (meshes are referenced mesh objects from grasshopper):


var integers = Enumerable.Repeat(meshes, 10);

Thanks,
Petras

Views: 2367

Replies to This Discussion

have you tried the Mesh.Duplicate() function? which will give you a duplicate of each mesh if you loop through the list of meshes, or are you looking for a shorthand to do this?

What exactly are you trying to do? Enumerable.Repeat(item, number) works with single items...but it sounds like you maybe want to repeat multiple items from a list?

Hi,

I just want to have the same output as duplicate battery in grasshopper.

According to Jens reply I found this:

http://wiki.mcneel.com/developer/rhinocommonsamples/duplicateobject

How to define number of copies for Mesh.Duplicate()?

Kind Regards,

Petras

sorry for asking, but then why not just use the duplicate data component? 

but anyway if you have a list and want duplicates per item, you will probably have to loop through your list, where you have a master loop that goes through your list, and then another loop which creates your duplicates of the current object in the master loop.

something like this:

DataTree _out = new DataTree<Mesh>();

for(int i=0;i<mesh.count;i++)

{

Mesh temp = mesh[i];

for(int j=0;j<nDup;j++)

{

_out.Add(temp,new GH_path(i));

}

}

A=_out;

Like so? Here it's neutral (will take all objects) but if you wanted to specify meshes for further transformation/operation in your script you of course can.

Ah, yes. So this one is like repeat data. The duplicate data could be done like so:

Thanks Jens and Dadiv for solutions for the issue.

The reason for not using a grasshopper component, is that I trying to learn C# and turn one grasshopper script in C# component.

Thank you,

Petras

One more question.

How to add a portion of list b to list a?

By portion I mean:

a.AddRange(//first N items of list b//); 

Thanks,

Petras

https://msdn.microsoft.com/en-us/library/21k0e39c(v=vs.110).aspx

So you would do b.GetRange(0, N) where zero is the place in the list you want to start from, and N is number of elements you want.

a.AddRange(b.GetRange(0, N));

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service