Hi, I am trying to turn off (hide) layers in a detail viewport using Rhinocommon. I though this would be simply a matter of activating the detail view, then setting Layer.IsVisible = False, then Layer.CommitChanges().
This does not seem to be the case. It seems Layer.IsVisible always refers to the layer’s main visibility settings, never its per-view visibility setting.
How does one do the equivalent of HideLayersInDetail using Rhinocommon?
Dale, thank you very much. I failed to mention that, for the time being, we’re still in Rhino 5. So I guess this is not exposed in R5? Would the following be the only way to do it in R5? (I’m using the GH C# component.)
I have been referring to your sample code here, but am still having trouble implementing SetPerViewportVisible for multiple detail views on a single page view. I find that only the last detail view activated appears to retain the visibility settings; the previous detail views seem to get reset. Also, confusingly, when I print the PerViewportIsVisible status as a test, everything still appears to be set to True.
I’m using the GH C# component for now; my code is below:
Here is an equivalent plug-in command that should work.
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
// Find the layer index by full path name
var layer_index = doc.Layers.FindByFullPath("TO-DRAW", -1);
if (-1 == layer_index)
return Result.Cancel;
// Get the layer object
var layer = doc.Layers[layer_index];
if (null == layer)
return Result.Failure;
// If the layer is off globally, then there is nothing to do
if (!layer.IsVisible)
return Result.Cancel;
// Find the page view
var page_view = doc.Views.GetPageViews().First(
item => item.PageName.Equals("PANEL_01", System.StringComparison.OrdinalIgnoreCase)
);
if (null == page_view)
return Result.Cancel;
// Process each detail
foreach (var detail in page_view.GetDetailViews())
{
var viewport_id = detail.Viewport.Id;
// Re-acquire the layer object, as the underlying
// object may have been modified
layer = doc.Layers[layer_index];
if (null != layer)
{
// If the layer is visible on the detail, turn it off
if (layer.PerViewportIsVisible(viewport_id))
{
layer.SetPerViewportVisible(viewport_id, false);
layer.SetPerViewportPersistentVisibility(viewport_id, false);
}
}
}
// Redraw if needed
var view = doc.Views.ActiveView;
if (null != view && view.ActiveViewportID == page_view.ActiveViewportID)
doc.Views.Redraw();
return Result.Success;
}
I implemented the script above and it works well for layers that are visible. However, when I try it for a layer which is off in the model view, the per-viewport visibility turns on again once the layer is turned on in the model view.
In other words it seems that “SetPerViewportVisible” and “SetPerViewportPersistentVisibility” do not affect layers which are not visible.
This is quite problematic, because it would be good to set the per-viewport visibility of layers regardless their current state in the model view.
Hi @Dale, thanks, I didn’t notice that layers can be turned off in model space only.
We will all change our behaviour in our studio, using this new feature and always leaving the global visibility “On”.