Control layer detail properties via script

Hello,

I’d like to control the properties of layers inside a detail (visibility, color) on a layout via RhinoScript but I didn’t find any relevant function. Is there any way to do that ?

(For context, I’m working on plans with a lots of small steps I need to represent. I managed to get a functional script to display correctly the current step in model space, but I’d like to not have to export every step manually)

Hi @solarius,

Since you’ve posted in the Scripting category, I’ll assume you are using Python. Met me know if this is not the case.

Python can access layer properties via RhinoCommon’s Layer class. There are a number of PerViewport methods that control per-viewport layer properties., such as color.

For example, if you wanted to change the color of a layer in the active detail, you could do something like this:

import Rhino
import scriptcontext as sc
import System

# Get the active view
view = sc.doc.Views.ActiveView
# Make sure a page view (layout) is active
if isinstance(view, Rhino.Display.RhinoPageView):
    # Get the id of the active detail viewport
    detail_id = view.ActiveDetailId
    # Make sure the detail, not the layout, is active
    if detail_id != System.Guid.Empty:
        # Some layer to modify
        current_index = sc.doc.Layers.CurrentLayerIndex
        # Copy the current layer
        layer = Rhino.DocObjects.Layer()
        layer.CopyAttributesFrom(sc.doc.Layers.CurrentLayer)
        layer.SetPerViewportColor(detail_id, System.Drawing.Color.Azure)
        # Modifying like this ensure Undo works...
        sc.doc.Layers.Modify(layer, current_index, False)
        sc.doc.Views.Redraw()      

Hope this helps.

– Dale

Hi Dale,

Exactly !

Thanks a lot ! I had a feeling it was possible with Rhinocommon, but not being familiar with it I was confused by the PerViewport and was not sure it was related to detail views.

Thanks for the demo script, I should have everything I need to build my script from that :slight_smile: