Grasshopper

algorithmic modeling for Rhino

Hi,

I am writing a code recursively analyze some curves at certain points and if they meet certain criteria then "shatter" them at those points. I think this means I need to use Curve  Split Method (IEnumerable(Double )).

 

The only problem is that I'm not sure how to work with IEnumerable(double).

 

I have a list of paramters : tlist as list(of double)

 

How is it possible to turn that list into an IEnumberable for use with the split method? Or is there another way?

 

Thanks!

Views: 702

Replies to This Discussion

Just use an array of numbers. If you are using the List(Of T) class to define a list of doubles use .toarray:

  a = crv.Split(t_list.toarray)

Thanks for the reply! Can I ask for a bit more help? It's not quite working yet.

t_list.toarray gives the correct parameters and using it as you suggest doesn't throw any warnings or errors, but I get a null value. Even though if I pull out that value(s) manually and use the shatter component it gives the correct result.  

 

I'm checking the parameters with the following code. Parameters are good. S is a list of curves and S(i) returns the curve with a domain including said parameters. But the result is null.

For Each dub As Double In tlist.toarray
            print(dub)
          Next
          A = S(i).split(tlist.toarray)

 

In fact if I put in the variables manually (e.g. A = S(7).split(3)) it returns the correct result...

I can get closer by making a nested FOR EACH loop that went into S(i) and tlist and performed the split individually... but this is a problem for curves with more than one point on them as it treats each split independently. e.g. a curve with two "shatter" points should produce 3 non-overlapping curves, but in this way you get 4 overlapping curves. I'm considering cutting my VB component in half and splicing the existing shatter component in the middle... Is there a way to call an existing component from inside a VB component?

Hi Kris,

do you think you could attach even a small sample?
This way it will be easier to figure out where to help.

Thanks,

- Giulio
____________
giulio@mcneel.com
McNeel Europe

of course!

 

Attachments:

I hope I understand the task, and in this case this should be one implementation.
Let's see if this is helpful,

- Giulio
_______________
giulio@mcneel.com
McNeel Europe

Attachments:

That got me going again. Thanks!

I'm still not exactly sure what I was doing wrong. I noticed that you use 'item access' for the crv input. Can you explain the benefits of doing that versus bring in the crv input as a list and handling it all in the component? Was that the root of my error? or was it the domain checking t > crv.Domain.Min AndAlso t < crv.Domain.Max ?

 

Thanks again,

Kris

Hi again,

well, 'Item access' was sufficient, so there was no reason to write more looping code. Double looping was not wrong by itself.

I am not completely sure what the code in the lower part was doing.
IEnumerable(Of T) is an interface that is implemented both in List(Of T) and in T() --that is array of T. This means that both an array and a list (and a lot more things) can go where an IEnumerable(Of T) is expected.

The last part of the code returns either the split result (an array) -- or an array with the original curve. This is to ensure that the script outputs always a one-level deeper collection structure, so for each curve input there is a tree branch.

The domain part is just to make sure we do not split right at the beginning or end of the parametrization of the curve. It is more a safety measure.

I hope this helps,

- Giulio
_______________
giulio@mcneel.com
McNeel Europe

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