Test layer.ParentLayerId against Guid.Empty in python?

Guid: Gets the ID of the parent layer. Layers can be organized in a hierarchical structure, in which case this returns the parent layer ID. If the layer has no parent, Guid.Empty will be returned.

I don’t see a Guid class documented in the rhino3dm documentation so how do I test a ParentLayerId against Guid.Empty?

Edit: maybe it’s falsey.

I did what I needed to do in another way.

I’ve been trying to avoid loading visible layers that are descendants of invisible layers when loading 3dm files into blender.

I’m using Nathan’s importer from GitHub - jesterKing/import_3dm: Blender importer script for Rhinoceros 3D files

Problem is that visible layers under an invisible layer are being imported because layer.Visible is true for those layers.

I thought I could walk up to the root from layer to find the first invisible layer then hide any layers between my starting layer and the first invisible layer encountered.

The problem is that even the simplest while loop to walk up the tree doesn’t terminate.

This code will not terminate. (the line colouring is not by design)

    if not import_hidden_layers:
        for layer in model.Layers:
            cur = layer
            while cur.Visible and cur.ParentLayerId:
                cur = model.Layers.FindId(cur.ParentLayerId)

I tried cur.ParentLayerId != Guid.Empty but Guid is not recognised
I tried is not None

My test.3dm file is very small and takes less than a second to load without my tree walk.

testBlenderImport.3dm (344.8 KB)

You can see that there is a sphere in the default layer and a cuboid in a visible layer (layer 06) under an invisible layer (layer 01) I only want to see the sphere in Blender.

is “Guid.Empty” something that isn’t falsey and does Layers.FindId(layer.ParentLayerId) return a valid layer if ParentLayerId == “Guid.Empty”?

I seem to be back to my initial question: how do I tell that a layer has no parent in the Python API?


My alternate solution was to run a script in the rhino file to hide visible layers that were under invisible layers but I don’t like that because it makes further edits more work for me.

For example: I can have a closed undercarriage door on one layer and an open door and lots of undercarriage parts under another layer. Two clicks can switch between undercarriage up and undercarriage down. If I run a script that hides all the undercarriage geometry layers then it would take many clicks to get all that geometry visible again.

Concerning regular Rhino/Python, the Guid class is not part of RhinoCommon, it is a subclass of the System class. Guid.Empty is actually System.Guid.Empty - whose value is 00000000-0000-0000-0000-000000000000

I don’t know how that works relative to rhino3dm though.

Yes, that looks like C#. I recognised Guid.Empty from C# land.

I tried importing system and System but they prevent the plugin from loading.

I tried a direct comparison against the string, “00000000-0000-0000-0000-000000000000”

but this code below seems to work (it isn’t stuck forever)

while cur.Visible and not str(cur.ParentLayerId) == "00000000-0000-0000-0000-000000000000":

so I’m going to play a bout to see if I can implement the layer hiding (as opposed to just not locking up Blender because I can do that by not running the import) :slight_smile:

This REALLY should be documented.

Anyway, I’m going to see if I can get this working now.


The loop doesn’t run at all -sigh (I put a counter in and raised an exception if count > 0)

A well: the sun is shining so I’m off outside.

Hi @jmcauley,

This is information on a Python GUID/UUID:


import rhino3dm
import uuid

model = rhino3dm.File3dm.Read('/Users/Dale/Downloads/test.3dm')

uuid_nil = uuid.UUID(int=0x0)

for layer in model.Layers:
    print('Name = {0}, Id = {1}'.format(layer.Name, layer.Id))
    if uuid_nil != layer.ParentLayerId:
        print('  Parent Id = {0}'.format(layer.ParentLayerId))

– Dale

Thanks Dale, I got my import working, I don’t see geometry in a visible layer if it is under an invisible parent and this is what I wanted.