C# Select objects by sublayer

Hi,

Any trick how to select objects of sublayer? Iam baking geometries through Elefront
i have 2 sublayers with same name but they belong to different main layers. So, is it possible to refer to specific Layer and its child?

0-BM_III.3dm (2.1 MB)
unnamed.gh (11.8 KB)

Your file do not have the layer structure you described.

Not sure if you want to select or reference geometry…

If you want to select geometry in identically named child layers quickly, you can do that by either using the child layer name as object name or by adding a user key and value.

bake.gh (25.9 KB)

Yes, in your suggestion, How is it possible to choose “Kansi” sublayer’s geometries which belong to “A” main layer?. if i just input “Kansi” to C#, then it will select all geometries regardless to where main layer they belong(By name).

My example uses the object name and not the layer.

If you want to reference with Elefront components, you could also use a layer filter such as *::KANSI

I’m no expert in C#, sorry.

1 Like

Ok Thanks

do you need a grasshopper approach or just a command / tool ?

there is
_selLayer
use it with commandline version
-_sellayer
and then use wildcard (Asterix)
-_sellayer "*Layer 01*"

this will select all layer pathes contain Layer 01
omit last Asterix to get childless Layers.

Yeah,

I actually need GH approach. Iam developing through C# script which can read geometries by layers and sub layer’s names and then give each geometry IFC properties. So, iam combining multiple plugins API’s by C#.

My guess is, you have to check all Layer-Full-Pathes
then use
https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_DocObjects_Tables_ObjectTable_FindByLayer_1.htm

If you want to limit the result further use the Layer-Index as Filter for a FindbyFilter or GetObjectList…Include the object-types that make sense for your usage.

this is one possible startingpoint:

https://developer.rhino3d.com/api/RhinoCommon/html/P_Rhino_DocObjects_Layer_FullPath.htm

https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_DocObjects_Tables_ObjectTable_FindByFilter.htm

https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_DocObjects_Tables_ObjectTable_GetObjectList.htm

maybe start with modifying this example:

1 Like

It’s very simple really, you first find the full layer path, then you search if the full_path_string contains the substrings “layer1_name” and “layer2_name”, if it does it contain both layer1 and layer2 you are getting an object which is in a specific sublayer (layer2) whose parent layer is layer1.
Just loop through all the objects that interest you should be very easy

1 Like