Grasshopper

algorithmic modeling for Rhino

C# How to add the return object of a function to a list of objects!

Hi All,

 

I'm trying to port a rhinoscript function that draws hexagon cells on a surface. the approach I took was to instantiate a list of polylines and I'm trying to add the polyline within a loop ,to the list.

 

The polyline is the return value from a function.

I get the error "cannot assign to 'Add' because it's a 'method group'.

 

Can anyone suggest a diferent way to do it or help me fixing the script?

 

Definition enclosed Many thanks in advance

 

Evert

Views: 616

Attachments:

Replies to This Discussion

Your sytnax is mimicking how you would add the variable to an array. The line in question...myC.Add = DrawHex(S, u, v, stp, dUspacing, dVspacing); ... is actually trying to assign the output of the DrawHex function as an "overload" to the add function*. Since A) a polyline isn't a function and B) you can't add a function to Add anyway, you see the error that you have. The Add method actually takes whatever you'd like to add as the argument, so the syntax would be like this... myC.Add(DrawHex(S, u, v, stp, dUspacing, dVspacing));

There's also another error in your code in the DrawHex function. With for loops in C#, the third argument is how the value your using to test whether to continue the loop is incremented (or decremented depending on what your doing). Right now this is how the beginning of your for loop looks... for(double t = 0; t <= 2 * Math.PI; stp++) If you look very closely, the variable that your using to evaluate the loop is t, yet you're incrementing the variable stp. Therefore, t never changes from 0 and you have an infinite loop. If you change the incrementing statement to t += stp then that will increment your variable by the step your looking for.

*this kind of syntax is fairly common in C# when it comes to event handlers
Hi Damien,

Thanks a lot for replying and for the explanation, I've changed the code and now it "works" ( It draws the hexagons but not over the whole surface and overlap) so I need to check the maths.

I'll post the definition when I make it work properly.

Thanks again and have a good day!

Evert

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