Grasshopper

algorithmic modeling for Rhino

Hello everyone!

I need a help with data trees!

I have a txt file with information about the bus stops timetables. I need to group each bus rout to have the first and last stops for each of them. Can anybody help me to solve this? I want to group according to the first number of each split item in grasshopper. Please help!:)

Thanks for any support 

Views: 1550

Attachments:

Replies to This Discussion

Hi Arusyak-

In-built components will work to map data structure onto your text file: to get the data in the correct order to start, you read the file and split each text line into its component parts...this makes a data branch for each entry. By flipping this matrix, you get unique lists for each column. Then you make unique paths for each item in one of your lists by first flattening it and then grafting it, extract this path information, and use the route integer as the replacing path. However, with the file size that you are using (and the profiler on, as in the below image), you can see how long this takes: the replace paths component can run very heavy:

Then, instead of running it twice, it's much lighter to use the "unflatten" tree component to apply the data structure to the second list.

With a little scripting, you can avoid some of this heaviness: I've added a quick one that does pretty much the same thing, but does so much more quickly. It's very little code:

private void RunScript(List<int> R, List<string> FS, List<string> LS, ref object FirstStop, ref object LastStop)
{

DataTree<string> FS_ = new DataTree<string>();
DataTree<string> LS_ = new DataTree<string>();

for (int Pth = 0; Pth < R.Count; Pth++)
{
FS_.Add(FS[Pth], new GH_Path(R[Pth]));
LS_.Add(LS[Pth], new GH_Path(R[Pth]));
}

FirstStop = FS_;
LastStop = LS_;

}

Attachments:

Hey David!

Thank you alot David. This is a great help!

David could you help me to retrieve the 3rd branch from the tree the same way that the bus stop times? I have tried to do it by myself, although it's a small script but I don't have any knowledge of C#.

Thanks in advance! 

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service