Grasshopper

algorithmic modeling for Rhino

Hello,

I have a question about extracting sublayer full name in Grasshopper. My rhino object is under main layer Default, then jhkh as second layer and lastly Layer01.

I'm able to extract the last layer name of this object as you can see from the image. However, instead of extracting only the very last one, I would like to get the layer name like this Default::jhkh::Layer01 in Grasshopper. (highlighted in the attached image)

Does anyone know how to do it but still couldnt find the way to do it. 

I've been searching and found the following discussions.

http://www.grasshopper3d.com/forum/topics/sub-layers

http://www.grasshopper3d.com/forum/topics/layer-and-sublayer-creati...

http://www.grasshopper3d.com/forum/topics/sub-layers?id=2985220%3AT...

Thank you very much.

Nicholas 

Views: 4631

Attachments:

Replies to This Discussion

Layer.FullPath should do it. the ObjectAttributes component in human will also give you this information if you don't want to script. For the full script, taking in an object guid g:

var object = RhinoDocument.Objects.Find(g);

var attributes = object.Attributes;

var layerIndex = attributes.LayerIndex;

var layer = RhinoDocument.Layers[layerIndex];

var fullPath = layer.FullPath;

Hello Andrew,

Thanks for your response. I tried to use ObjectAttributes component from Human. However, it still gives me the layer name where the object is in instead of the full layer name ( Default::Layer01::Layer02) Is it possible to get full path through ObjectAttributes ?

Also, I'm not sure if I did something wrong with the script you wrote, somehow I couldnt make it work.

Thanks again.

Nicholas

Hi Nicholas,

Look at the FP output of the ObjectAttributes component in your image. It is the Layer Full Path, which I think is what you are looking for

Hello Andrew, do you know if there is a way to convert full layer name to object ID? I assume that the object ID also corresponds to the layer full name? 

object id and layer full name have nothing to do with each other. you can have many objects with different ids on the same layer, so there cannot be a one-to-one mapping from layer full name to object id. Unless I am misunderstanding your question?

I found this (same as what you used?), with a working, modifiable C# component attached: http://www.grasshopper3d.com/forum/topics/access-to-the-attributes-...

Added 'path' output as follows, and managed to hack together a Python version as well.

C++ version:

int lIndex = doc.Objects.Find(guid).Attributes.LayerIndex;
Print(doc.Layers[lIndex].Name);
path = doc.Layers[lIndex].FullPath;

Python version:

import System.Guid as Guid
import Rhino
doc = Rhino.RhinoDoc.ActiveDoc
lIndex = doc.Objects.Find(guid).Attributes.LayerIndex
print doc.Layers[lIndex].Name
path = doc.Layers[lIndex].FullPath

Attachments:

Hi Joseph, this is great! Thank you very much!!!

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