How to get the values of a Rhino Object using C#

Hello guys,

I’m trying to get the keys and values of the Rhino object using the C# script and I am now managed to extract the keys: PTCODE, PTELEV, PTNAME.
However, I couldn’t find the corresponding values by accessing the attributes properties.
If there is someone who can help me with it, I’d appreciate it!

Thanks a lot!

attached below is my code which managed to extract the keys:

Rhino.RhinoDoc doc = Rhino.RhinoDoc.ActiveDoc;
Rhino.DocObjects.RhinoObject[] rhobjs = doc.Objects.FindByLayer(name);

var keys = rhobjs[2].Attributes.GetUserStrings();
B = keys;

1


map.3dm (428.8 KB)
RhinoDocLayerFinder2.gh (3.1 KB)

Use the attached as a start - add anything more.

LayersAndRObjects_EntryLevel_V1.gh (7.2 KB)

Thanks for your reply,
I’m also wondering where can I get the values (12.38, 15) that are displayed on the image.
or which property I can apply in order to get them?

Thank you!

Found it, it’s the “.Attributes.GetUserString()” method.!
Thanks!

Found a couple of minutes more for the trad update.

LayersAndRObjects_EntryLevel_V1A.gh (117.2 KB)

BTW: The proper way to deal with some general case is to define a suitable class (see a simple demo one inside C#) and then do P/LINQ (flat of nested) queries: GroupBy, OrderBy and the likes.

1 Like

Thanks for your demonstration!
Got another question if you don’t mind.
I am trying to extract the key, values, and the corresponded geometry (in this case, it’s a 3dpoint) from the InstanceObject by using C#; I’m wondering which method or property I could apply in order to get the 3dpoint geometry?

Thanks

You mean that you have Instance Definitions to play with? (Blocks) - if so the Find should be a bit more focused.

Yeah, but I still can’t get it right…
Initially, I was planning to get the geometry by using the “.Explode” method; However, this strategy seems only applicable in InstanceObject…

The data type I got from the "doc.Objects.FindByLayer(name) " method is a “RhinoObject”, so
I think this idea can’t work…
map.3dm (441.8 KB)
RhinoDocLayerFinder2.gh (4.8 KB)

You date the wrong girl (an InstanceReference is the Definition placed in the doc, while the Definition itself is the “template”):

Anyway … if you can’t do it (it’s that easy, mind) … I’ll provide a full Instance Definition related thingy later on (how to find, how to get things, how to do chaos, how to do bad things … etc etc).

BTW: are you familiar with classes and LINQ? (in order to properly query the Instance Definitions found).

BTW: Obviously you can take the long way home: Find by Layer and then query by ObjectType:

In the mean time I have a small C# challenge for you: Assume that you have nested Layers(real-life and the likes) .By what means the path {3;7} would become the correct one {3;6;7}? Is it a small Recursion the answer? Is it Karma? Is it something else?