Grasshopper

algorithmic modeling for Rhino

How can I keep a value from the first iteneration and use it on the next one?

Hello:

I have a rather large definition that combines Kangaroo with Hoopsnake. In this definition I need to keep the original length of the "kangaroo springs" and use it on all the following iterations in order to do a correct physical simulation. This "spring lenght" is obtained halfway in iteration 0 and does not belong to input/output loop of hoopsnake, therefore it cannot be extracted from the hoopsnake history.

I am looking at a clean and straightforward way to extract this value at the start of the definition and it use it while looping the definition.

Ideally the definition would  automatically bake this "spring length"  somewhere inside or outside Rhino in iteration 0 and read it without modifying on the next iterations. However achieving this has proven elusive to me.

I have tried to solve this in the following ways:

Duplicated definition: Create two copies of the same part that deals with the spring length and use one for iteration 0 and another for the the following ones. However I do not consider this a clean and straightforward way to solve the problem.

Ghowl: Ghowl has an excel read and write component. It works well except for the fact that I need to have excel open (which I do not believe should be necessary for such a simple task) and more importantly, the fact that it duplicates the time it takes to compute the solution. Since this is a definition that runs through about 500 iteration speed is quite important.

Panels: I am currently using panels to write a text file and then call it back with a "read file" component. This approach is straightforward and quite fast. The problem is that there is no way (at least to the extend of my knowledge) to stop the panel from rewriting the file with every iteration, and thus destroying the original spring lenght.

Any help on this regard would be greatly appreciated. Also if I miss to explain something please let me know.

Thanks

Diego

Views: 575

Replies to This Discussion

You could try your luck with a scripting compnent, e.g. as attached

Best regards

  Stefan

Attachments:

Hello Stefan:

It worked perfectly. Thank very much.

There is only one nuisance, the script requires about 20 seconds to write a list of 2000  number. I believe that perhaps the conversion of those number to string in order to write them is slowing things down. Perhaps the input could be changed somehow into numbers and speed up the process. I tried to do it myself but failed.

Anyhow I will keep using it even if it slow 20 second the first iteration.

Thank you again.

Diego

Thanks for the feedback.

I changed the C# code a bit (using System.IO.StreamWriter instead of System.IO.File.AppendAllText), and it should run faster now...

Regards

  Stefan

Attachments:

Stefan:

The script now performs in the millisecond range and works flawlessly writing and reading. Thank you very much for your help.

Sincerly

Diego

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