Grasshopper - delete last layer in sublayer full path name

Is there a way using Grasshopper to delete the last layer from the sublayer full path name ? To complicate things the number of sublayers can vary and the name of the last sublayer can also vary.

I need to be able to select breps using the layer one layer up from the last layer in the full path text string.

If someone can point me in the right direction it would be most appreciated.

Chris Holtorf


Here is a first step in the right direction, assuming you only have one level of sublayers.

You don’t necessarily need to delete the last sublayer of each group in order to select objects from the first to last sublayer in GH.

FirstToLastSublayer.3dm (23.2 KB) (10.1 KB)

It would have been nice of you to supply a list of paths. After adding some deeper nested layers, I used @magicteddy’s paths instead (thank you!). NOTE: It appears to me that his C# Script works only when the GH file is opened and otherwise ignores layer changes? Your might find the standard GH Object Details component handy for getting layer names.

The standard GH Text Split works only with single characters. Using two colons (“::”) as the separator produces a messy result so I wrote a simple Python text splitter: pTxtSplit:

a = T.split(S)

With it, I get this:

layers_2023Feb5a (12.9 KB)

P.S. Here is the same code in a cluster: PLPath (Parent Layer Path, green group)

layers_2023Feb5b (14.6 KB)

It works with single paths too, of course. Connect List Item instead.

1 Like

Thanks, I’ll give this a try.


OK I completely misunderstood the initial problem, I thought the purpose was to access those layers - one up from the last sublayer in each group :man_facepalming:


The Replace Text trick can avoid the custom Python code, FWIW. Too bad Text Split does not accept separators with several characters.

Yes, there is probably a RhinoDoc event to trigger the update of the layer list automatically if required.

Sorry about the ambiguity of my question. I need to access all of the layers in the full name path except the last one.

I shouldn’t ask questions so late in the evening :grinning:

However, what you sent will be very useful later on in this project so once again, thanks.


So is that not the same as the path to a layer’s parent? Clarity about your objective is crucial.

I should have sent a graphic highlighting what I needed.

I need to remove the crossed out layers from the layer map full path names (last layer from the sublayer full path name).


You should have posted a GH file. Does my code fail to do what you want?