Layer ID not change

Hi,

I try change de Layer ID , but for some reason the id dont change:

            var layer = doc.Layers.FindName("ServiceLayer");
            layer.Id = new Guid("7F7C7FE1-979E-432A-AB63-F64836EA66ED");
            var idString = layer.Id;
            MessageBox.Show(idString.ToString());

Am i doing something wrong?

Thanks

HI Matrix
You can check the layer.IdIsLocked Property. If the ID is locked. You can try to delete the original layer, Create a new layer with the new ID and place it at the original index position.

@603419608

Thank you,

You are right and the layer id is lock, but I don’t understand why, I’m creating this layer at the same time, I just want to assign a fixed ID to this layer:

        doc.Layers.Add("ServiceLayer",Color.Transparent);
        var layer = doc.Layers.FindName("ServiceLayer");
        layer.Id = new Guid("7F7C7FE1-979E-432A-AB63-F64836EA66ED");
        var idString = layer.Id;
        MessageBox.Show(idString.ToString());

I can’t find any way to assign the id at the same time as the layer creation.

Thank you

Why do you need to do this?

– Dale

Hi @dale

Basically, I want to create some layers to use with my plugin, to make it easier I was thinking of creating them with fixed ids, whenever rhino is opened it checks if these layers exist, if don’t, they create them with fixed ids.

Anyway, I also wish these layers were not exposed to user, or at least editable by the user, and i’m not getting that.

With the layer.table event I got the user to not be able to edit almost everything, but I can’t stop the user from selecting the layer, in which case he can delete the layer and that won’t be good for my plugin.

Thanks

Hi @MatrixRatrix You can force lock layers to make them completely uneditable by a user if you play around with the RhinoEvents, would that suit your needs?

@csykes

I’ve also tried, the problem is that I can’t avoid the selection by the user with the events, and the user can select and delete, I’m debating this in another topic.

Thanks

Create a layer with a fixed ID?like this

private void RunScript(ref object A)
  {
    var layerIds = Rhino.RhinoDoc.ActiveDoc.Layers.Select(L => L.Id);
    var guid = new Guid("7F7C7FE1-979E-432A-AB63-F64836EA66ED");
    if( !layerIds.Contains(guid))
    {
      //Create new layer.
      var layer2 = new Rhino.DocObjects.Layer();
      layer2.Id = guid;
      layer2.Name = "ABC";
      layer2.Color = System.Drawing.Color.Red;
      int newIndex = Rhino.RhinoDoc.ActiveDoc.Layers.Add(layer2);
    }

    A = Rhino.RhinoDoc.ActiveDoc.Layers.FindName("ABC").Id;
  }

Thank you