# Hiding Reference Layers in Layers Tree

**URL:** <https://discourse.mcneel.com/t/hiding-reference-layers-in-layers-tree/179892>\
**Category:** Rhino Developer\
**Tags:** windows\
**Created:** [April 11, 2024, 7:37pm UTC](https://discourse.mcneel.com/t/hiding-reference-layers-in-layers-tree/179892 "2024-04-11T19:37:57Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![LarryL](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/larryl/32/689990_2.png) [@LarryL](https://discourse.mcneel.com/u/LarryL)\
**Post date:** [April 11, 2024, 7:37pm UTC](https://discourse.mcneel.com/t/hiding-reference-layers-in-layers-tree/179892/1 "2024-04-11T19:37:57Z")

</div>

Is there any way to prevent a reference layer that is added in plug-in code (not via a worksession) from showing up in the Rhino layers tree even though it is added to the document? A secret layer of sorts?  
Thanks, Larry

---

<div class="post-metadata">

**Author:** ![csykes](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/csykes/32/485543_2.png) [@csykes](https://discourse.mcneel.com/u/csykes)\
**Post date:** [April 11, 2024, 9:22pm UTC](https://discourse.mcneel.com/t/hiding-reference-layers-in-layers-tree/179892/2 "2024-04-11T21:22:15Z")

</div>

I can’t recall if I’ve tried this, but have you tried using [`Layer.IsVisible`](https://developer.rhino3d.com/api/rhinocommon/rhino.docobjects.layer/isvisible?version=8.x)?  
This seems like it should do what you’re asking.

---

<div class="post-metadata">

**Author:** ![LarryL](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/larryl/32/689990_2.png) [@LarryL](https://discourse.mcneel.com/u/LarryL)\
**Post date:** [April 11, 2024, 10:15pm UTC](https://discourse.mcneel.com/t/hiding-reference-layers-in-layers-tree/179892/3 "2024-04-11T22:15:20Z")

</div>

I guess I assumed that this set the visibility of the objects on the layer, like clicking the light bulb next to the layer, rather than hiding the existence of the layer itself. Is that not the case?

---

<div class="post-metadata">

**Author:** ![csykes](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/csykes/32/485543_2.png) [@csykes](https://discourse.mcneel.com/u/csykes)\
**Post date:** [April 11, 2024, 10:29pm UTC](https://discourse.mcneel.com/t/hiding-reference-layers-in-layers-tree/179892/4 "2024-04-11T22:29:34Z")

</div>

Ah yes sorry you’re right. I was looking at this from the wrong angle 😊.

---

<div class="post-metadata">

**Author:** ![menno](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/menno/32/770384_2.png) [@menno](https://discourse.mcneel.com/u/menno)\
**Post date:** [April 12, 2024, 7:35am UTC](https://discourse.mcneel.com/t/hiding-reference-layers-in-layers-tree/179892/5 "2024-04-12T07:35:49Z")

</div>

Why do you want to do that, what are you trying to achieve? There may be other ways to do this, but I don’t think a “secret layer” is an option.

---

<div class="post-metadata">

**Author:** ![LarryL](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/larryl/32/689990_2.png) [@LarryL](https://discourse.mcneel.com/u/LarryL)\
**Post date:** [April 12, 2024, 11:36am UTC](https://discourse.mcneel.com/t/hiding-reference-layers-in-layers-tree/179892/7 "2024-04-12T11:36:04Z")

</div>

Hi Menno, thanks for your input. Yes, this approach was more for expediency than anything else. We create some reference layers in our plug-in at initialization, that are used for certain pieces of functionality. If someone is not using that functionality, then those layers are technically not needed (and some users have expressed a desire not to have to see them at all in the layers tree in that case or I suppose even when they are needed). The initial approach was to create the layers lazily only when the functionality that requires them is needed. Unfortunately this has wider implications for the code which would require a fair bit of restructuring and then testing. For what seemed like a functionality request with relatively low significance, it seemed a lot easier to offer a way to just let the user hide them from showing up in the layers tree without actually removing them.

---

<div class="post-metadata">

**Author:** ![menno](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/menno/32/770384_2.png) [@menno](https://discourse.mcneel.com/u/menno)\
**Post date:** [April 12, 2024, 12:25pm UTC](https://discourse.mcneel.com/t/hiding-reference-layers-in-layers-tree/179892/8 "2024-04-12T12:25:28Z")

</div>

Hold your horses, it looks like it is possible with the C++ SDK. Let me see if I can create a useful example.

---

<div class="post-metadata">

**Author:** ![david.birch.uk](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/david.birch.uk/32/610361_2.png) [@david.birch.uk](https://discourse.mcneel.com/u/david.birch.uk)\
**Post date:** [April 12, 2024, 12:26pm UTC](https://discourse.mcneel.com/t/hiding-reference-layers-in-layers-tree/179892/9 "2024-04-12T12:26:28Z")

</div>

Also following this thread, we take a very similar approach to @LarryL for our CNC plugin ZebraCut.

We provide the user with a big “clear Layers” which deletes the reference layers whenever they wish.  
We also call that routine frequently before large operations. Can share code if helpful

---

<div class="post-metadata">

**Author:** ![LarryL](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/larryl/32/689990_2.png) [@LarryL](https://discourse.mcneel.com/u/LarryL)\
**Post date:** [April 12, 2024, 12:42pm UTC](https://discourse.mcneel.com/t/hiding-reference-layers-in-layers-tree/179892/10 "2024-04-12T12:42:37Z")

</div>

Hi David, thanks for your input. That’s an interesting approach. If the user wants to delete the reference layers but there is useful information on them do you let them or warn them it will delete important info? If you do an operation that requires the reference layers do you just create them again automatically?

Thanks Menno, eager to see what you find.

---

<div class="post-metadata">

**Author:** ![menno](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/menno/32/770384_2.png) [@menno](https://discourse.mcneel.com/u/menno)\
**Post date:** [April 12, 2024, 12:47pm UTC](https://discourse.mcneel.com/t/hiding-reference-layers-in-layers-tree/179892/11 "2024-04-12T12:47:01Z")

</div>

In the C++ SDK you can apply a layer filter to show any layers that pass the filter. In the command below a small example of what is possible:

Run this once to create a red layer called `"Lock+Off to hide me"`. If you then lock the layer and hide its contents by clicking the lamp to off, and run the command again, the layer will be filtered off the list.

It will reappear when the file is reloaded, or any time Rhino itself applies a filter. This is done when the user sorts the layer table for example, or applied a filter of their own. So you may want to do something when the file is loaded, also listen for layer table events and take action accordingly.

I’m the first to say that this feels a bit like a hack, but it gets you towards where you want to be.

```cpp
  CRhinoCommand::result RunCommand(const CRhinoCommandContext& context) override
  {
    ON_Color c(255, 0, 0);

    int id = context.m_doc.m_layer_table.AddLayer(L"Lock+Off to hide me", c, true);
    const CRhinoLayer& l = context.m_doc.m_layer_table[id];    

    CRhinoLayerFilter filter(context.m_doc.RuntimeSerialNumber());
    
    unsigned int lock = (unsigned int)CRhinoLayerFilter::FilterType::Unlock;
    unsigned int off = (unsigned int)CRhinoLayerFilter::FilterType::On;
    unsigned int lockAndOff = lock | off;

    filter.SetFilterType((CRhinoLayerFilter::FilterType)lockAndOff);
    filter.SetSortType(CRhinoLayerFilter::SortType::None);
    filter.SortAndCull(false);

    ON_SimpleArray<const CRhinoLayer*> list;
    context.m_doc.m_layer_table.GetSortedList(true, false, list);
    for (int i = 0; i < list.Count(); ++i)
    {
      const CRhinoLayer* l = list[i];
      RhinoApp().Print(L"Layer %d %s\n", i, l->Name());
    }
    
    return success;
  }

```

---

<div class="post-metadata">

**Author:** ![LarryL](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/larryl/32/689990_2.png) [@LarryL](https://discourse.mcneel.com/u/LarryL)\
**Post date:** [April 12, 2024, 1:02pm UTC](https://discourse.mcneel.com/t/hiding-reference-layers-in-layers-tree/179892/12 "2024-04-12T13:02:31Z")

</div>

Thank you @menno

---

<div class="post-metadata">

**Author:** ![david.birch.uk](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/david.birch.uk/32/610361_2.png) [@david.birch.uk](https://discourse.mcneel.com/u/david.birch.uk)\
**Post date:** [April 12, 2024, 1:16pm UTC](https://discourse.mcneel.com/t/hiding-reference-layers-in-layers-tree/179892/13 "2024-04-12T13:16:32Z")

</div>

Yeah we allow users to always delete reference layers - no warnings.

Any information on them should be regenerated afresh during any operation because the users original geometry may have changed.

Thank you @menro that looks interesting - I wonder if Rhino Common provides the same API

---

<div class="post-metadata">

**Author:** ![menno](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/menno/32/770384_2.png) [@menno](https://discourse.mcneel.com/u/menno)\
**Post date:** [April 12, 2024, 1:21pm UTC](https://discourse.mcneel.com/t/hiding-reference-layers-in-layers-tree/179892/14 "2024-04-12T13:21:24Z")

</div>

RhinoCommon does not provide this AFAICS.

---

<div class="post-metadata">

**Author:** ![dale](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/dale/32/772741_2.png) [@dale](https://discourse.mcneel.com/u/dale)\
**Post date:** [April 12, 2024, 3:19pm UTC](https://discourse.mcneel.com/t/hiding-reference-layers-in-layers-tree/179892/15 "2024-04-12T15:19:49Z")

</div>

Hi @LarryL,

A layer has a “is visible in UI” property that is not exposed anywhere. This property is runtime only - it is not archived in 3dm files. When layers are filtered, either by using the Layers panel or some C++ class, this property is used.

I can expose this property to RhinoCommon. No guarantees this flag will survive layer filtering, however.

[https://mcneel.myjetbrains.com/youtrack/issue/RH-81522](https://mcneel.myjetbrains.com/youtrack/issue/RH-81522)

– Dale

---

<div class="post-metadata">

**Author:** ![LarryL](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/larryl/32/689990_2.png) [@LarryL](https://discourse.mcneel.com/u/LarryL)\
**Post date:** [April 12, 2024, 3:27pm UTC](https://discourse.mcneel.com/t/hiding-reference-layers-in-layers-tree/179892/16 "2024-04-12T15:27:39Z")

</div>

Hi @dale, I think this would serve our purpose very nicely, thank you!

---

<div class="post-metadata">

**Author:** ![jstevenson](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/jstevenson/32/773002_2.png) [@jstevenson](https://discourse.mcneel.com/u/jstevenson)\
**Post date:** [April 12, 2024, 4:53pm UTC](https://discourse.mcneel.com/t/hiding-reference-layers-in-layers-tree/179892/17 "2024-04-12T16:53:30Z")

</div>

We too could make use of that new RhinoCommon property. Thanks @dale @menno !
