Permalink Reply by Rafi on January 21, 2010 at 1:55pm
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);
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]]);
}