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.
Question:
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?
-PS
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.