Grasshopper

generative 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.

Tags: names, object, reading

Views: 559

Reply to This

Replies to This Discussion

Hi Rafi,

object names are stored in the ObjectAttributes (alongside Layer, Grouping, Linetype etc.) and they are completely ignored by Grasshopper. The only way to extract the Object name, is to feed the object into a GUID parameter, then feed the Guid into a Script component, access the rhino document, locate the object, get the attributes and have a look inside with a VB or C# script.

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

I am not very familiar with the code! Can you possibly give some clues about this, or perhaps an example?
Can someone help me?

I have no idea how such a VB script should look like and I need urgently a prior notices.
Something like this (just writing it from the top of my head):

Dim obj_ref As New MRhinoObjRef(obj_id)
If (obj_ref Is Nothing) Then Return

A = obj_ref.Object().Attributes().m_name


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

This is VB.NET accessing the old Rhino SDK. These days Grasshopper uses the new Rhino SDK.Now this code would look like:

 

Dim obj_ref As New DocObjects.ObjRef(obj_id)

If (obj_ref.Object() Is Nothing) Then Return

A = obj_ref.Object().Attributes().Name

 

There are a lot of books on learning VB.NET, and a lot of web resources. There's not a lot of documentation on learning our SDK. We have documentation explaining what most classes and functions do, sometimes even with example code, but nothing didactic.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

the code i put down is  always giving compile errors. can you send me a script that reads names of breps?
Thanks David,
I tried my best but without success!
Maybe you can give me a hint.
Attachments:


--
David Rutten
david@mcneel.com
Poprad, Slovakia
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

RSS

Translate

Search Grasshopper

Photos

  • Add Photos
  • View All

© 2013   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service