This is the file I tested,you can try it. layervisabletest.3dm (35.3 KB)
This is mycode:
public class MyRhinoCommand : Command
{
public MyRhinoCommand()
{
// Rhino only creates one instance of each command class defined in a
// plug-in, so it is safe to store a refence in a static property.
Instance = this;
}
///<summary>The only instance of this command.</summary>
public static MyRhinoCommand Instance { get; private set; }
///<returns>The command name as it appears on the Rhino command line.</returns>
public override string EnglishName => "MyRhinoCommand";
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
var layerIndex = doc.Layers.FindByFullPath("test", -1);
if (layerIndex == -1)
{
layerIndex = doc.Layers.Add("test", System.Drawing.Color.Red);
}
var topView = doc.Views.Where(v => v.ActiveViewport.Name == "Top").FirstOrDefault();
var secondView = doc.Views.Where(v => v.ActiveViewport.Name == "Perspective").FirstOrDefault();
var layer = doc.Layers.FindIndex(layerIndex);
layer.SetPerViewportVisible(topView.ActiveViewportID, false);
layer.SetPerViewportVisible(secondView.ActiveViewportID, true);
return Result.Success;
}
}
Perviewport visibility currently only works with detail viewports. There are large portions of the core that would need to be adjusted to accommodate for this in standard modeling views