Grasshopper

algorithmic modeling for Rhino

Hello together,
How can I reading object names of existing objects in model space and following Organize all of them according name?

Example: Line_01; Line_02; Line_03, etc.

Views: 4137

Replies to This Discussion

Thanks David,
It works fine, but I want to import the object names
to rearrange the objects according the numerical index.
How I can reorganising my list of curves?
Example of imported object names:
0 Curve_3.1
1 Curve_5.1
2 Curve_1.1
3 Curve_4.1
4 Curve_2.1
etc.
If the sorting works on just strings, it's easy. You create a List of names and call Sort() on it. If your sorting is more complex, you'll have to perform some magic to turn your object names into numbers.

Probably something along the lines of:

//-----------------------------------
int[] index_map = new int[names.Length];
double[] key_map = new double[named.Length];

for (int i = 0; i < names.Length; i++)
{
string trimmed = names[i].Replace("Curve_", string.Empty);
double value = double.Parse(trimmed);

index_map[i] = i;
key_map[i] = value;
}

Array.Sort(key_map, index_map);
//-----------------------------------

Now you'll have two arrays, one contains sorted values, and the index_map contains the sorted indices of the original names array. To now iterate over the sorted names, simply run your indices through the index_map and you're done:

for (int i = 0; i < names.Length; i++)
{
Print(names[index_map[i]]);
}


--
David Rutten
david@mcneel.com
Poprad, Slovakia

I know this thread has been before the update; has a component similar to one described above been added to the new grasshopper?

you can use Horster

Hello David,

Thank you for Help!
I don`t having a idea how to using the code.
And how the script must be integrated to reorganising the curve list.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service