Site Tools


Lock a Layer

Developer: .NET
Summary: Demonstrates how to lock a layer.
Notice: The Rhino.NET SDK is deprecated in Rhino 5. This example adapted for the new RhinoCommon SDK is here.

Example

VB.NET

Public Overrides Function RunCommand(ByVal context As RMA.Rhino.IRhinoCommandContext) As RMA.Rhino.IRhinoCommand.result
 
    ' Prompt the user for the name of a layer to lock
    Dim gs As New MRhinoGetString
    gs.SetCommandPrompt("Name of layer to lock")
    gs.GetString()
    If (gs.CommandResult() <> IRhinoCommand.result.success) Then
      Return gs.CommandResult()
    End If
 
    ' Get the input string and validate it
    Dim layer_name As String = gs.String()
    layer_name.Trim()
    If (String.IsNullOrEmpty(layer_name)) Then
      Return IRhinoCommand.result.nothing
    End If
 
    ' Get the document's layer table
    Dim layer_table As MRhinoLayerTable = context.m_doc.m_layer_table
 
    ' Try finding the layer in the layer table
    Dim layer_index As Integer = layer_table.FindLayer(layer_name)
    If (layer_index < 0) Then
      RhUtil.RhinoApp.Print(String.Format("Layer {0} does not exist." + vbCrLf, layer_name))
      Return IRhinoCommand.result.nothing
    End If
 
    ' See if the layer is already locked
    Dim layer As IRhinoLayer = layer_table(layer_index)
    If (layer.IsLocked()) Then
      RhUtil.RhinoApp.Print(String.Format("Layer {0} already locked." + vbCrLf, layer_name))
      Return IRhinoCommand.result.nothing
    End If
 
    ' Make a copy of the layer
    Dim locked_layer As New OnLayer(layer)
 
    ' Set the layer state to locked
    locked_layer.SetLocked(True)
 
    ' If the layers are in a hierarchical manner, do this
    ' so the layer's visibility is not toggled.
    locked_layer.SetVisible(layer.m_sublayer_bVisible)
 
    ' Modify the existing layer using the properties of our copied one
    If (layer_table.ModifyLayer(locked_layer, layer_index)) Then
      context.m_doc.Redraw()
    End If
 
    Return IRhinoCommand.result.success
 
  End Function


developer/sdksamples/locklayer.txt ยท Last modified: 2016/03/16 by sandy