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?
@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 :(";
}
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?
@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)