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: 4076

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

I tried to replicate your script but I'm getting the following error:

1. Error (CS0246): Não foi possível localizar o nome do tipo ou do espaço de nomes 'MRhinoObjRef' (está a faltar uma directiva using ou uma referência à assemblagem?) (line 72)

(rough translation)

1. Error (CS0246): It wasn't possible to locate the name of the type or of the namespace 'MRhinoObjRef' (a directive using or a reference to the assemblage is missing?) (line 72)

What am I doing wrong?

This is very old code using a previous version of the Rhino .NET SDK. We're using RhinoCommon these days which requires a different approach.

Without testing, I guess the current code would look like:

private void RunScript(Guid id, ref object A)

{

  ObjRef objRef = new ObjRef(id);

  if (objRef.Object() != null)

    A = objRef.Object().Attributes.Name;

  else

    A = "id does not refer to a loaded Rhino object";

}

Note that you'll have to set the type hint for the input to Guid from within the input context menu.

Thanks David! It worked perfectly!

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