Hide layer in detail view with Grasshopper

Hi

I am wondering if it is possible to ‘hide layer in detail’ using Grasshopper so that I can isolate a single layer per layout.

I have several layouts that utilise the same naming convention as the layers. So in layout 001, I want to turn off layers 002 & 003. The challenge is that it must be the layer’s ‘Detail on’ setting, not the standard (model space) on/off.

In Grasshopper, I can get the detail views using Drafthorse (@jokamm). OOTB components can be used to get the layers I want to hide. But I’m stuck trying to hide the layer in the detail view. It doesn’t seem possible with OOTB components and I don’t believe Drafthorse, Elefront or Human has this capability. Any ideas how to resolve?

Failing this, if there is a way to ‘hideInDetail’ that workflow could also work.

Detail view.3dm (300.0 KB)
Detal view.gh (31.0 KB)

Hi @parametricmonkey1,

I have not used them yet but I believe the new Layer Visibility component introduced in 8.9 was it? Will do the trick I believe

See this post:

No that doesn’t work as it works on model layer visibility, not layer visibility within a detail view.

I think it needs to be scripted using the SetPerViewportVisible method.

Ahh okay, good to know

@parametricmonkey1
You’re on the right track with SetPerViewportVisible. I got the following working quickly, so it’s now a matter of wrapping it up nicely and giving it some guardrails. Tricky part, as far as I can tell, is that the per-viewport toggle is not included in the Grasshopper.Rhinoceros.Model.ModelLayer object’s methods currently. It’s certainly possible, but hasn’t been done yet. In the meantime, you have to get the Rhino Layer instead to do SetPerViewportVisible.

private void RunScript(Guid x, object Layer, bool toggle, ref object a)
    {
        // Try to cast the input to a Grasshopper Layer
        Grasshopper.Rhinoceros.Model.ModelLayer ghLayer = Layer as Grasshopper.Rhinoceros.Model.ModelLayer;

     if (ghLayer != null)
    {
        // Get the active Rhino document
        Rhino.RhinoDoc doc = Rhino.RhinoDoc.ActiveDoc;

        if (doc != null)
        {
            // Try to find the layer by name
            int layerIndex = doc.Layers.FindByFullPath(ghLayer.Path, -1);
            if (layerIndex >= 0)
            {
                // Retrieve the layer
                Rhino.DocObjects.Layer rhLayer = doc.Layers[layerIndex];
                rhLayer.SetPerViewportVisible(x,toggle);
                a = "Success"; 
                return;
            }
        }
    }
    a= "failure :(";
    }
1 Like

Thanks @jokamm that is great.

Not sure if I am doing something wrong, but the script is setting the visibliity of just one of the input layers per detail view. I have (at least) two layers that need to be turned off per detail view. Possibly need to interate over the SetPerViewportVisible method?

The C# component was expiring the Query Model Layers components so I enabled the manual Query to see if that helps, but still the same issue.

Detal view v2.gh (46.0 KB)

@parametricmonkey1 I think you were having datatree matching issues. It would probably be possible to graft the detail input and put two layers in each matching branch, but I also got it to work by changing the Layer input to a list and iterating through, like you suggest above.
Detail view v3.gh (23.8 KB)

@parametricmonkey1 however, if that’s the route this component takes, it would probably make sense to have the boolean input match the data structure of the layer input so that you could selectively turn layers on and off on the same detail. Here’s a version with the data structure aligned for the intended effect
Detail view v4.gh (27.2 KB)

… and one more variation for good measure, demonstrating different states for different layers on the same detail
Detail view v5.gh (26.1 KB)

2 Likes

@jokamm that’s perfect. Thankyou.

It would be great if this could be added to the next version of Drafthorse as I’m sure people would find it valuable. Thanks again.

1 Like