# Lock selected layer

**URL:** <https://discourse.mcneel.com/t/lock-selected-layer/112192>\
**Category:** Serengeti (Rhino BETA)\
**Created:** [November 13, 2020, 11:54am UTC](https://discourse.mcneel.com/t/lock-selected-layer/112192 "2020-11-13T11:54:13Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Piotr](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/piotr/32/635473_2.png) [@Piotr](https://discourse.mcneel.com/u/Piotr)\
**Post date:** [November 13, 2020, 11:54am UTC](https://discourse.mcneel.com/t/lock-selected-layer/112192/1 "2020-11-13T11:54:14Z")

</div>

![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/a/1/9/a19a5bf05689dfa22d1169cd449720e897f0dd8b.png)  
Can we have this panel upgraded with _ **LOCK selected layer** _, please?  
It is an ArhiCAD feature which I am using often on a files I don’t know the layer structure.

---

<div class="post-metadata">

**Author:** ![3dsynergy](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/3dsynergy/32/758178_2.png) [@3dsynergy](https://discourse.mcneel.com/u/3dsynergy)\
**Post date:** [November 13, 2020, 7:50pm UTC](https://discourse.mcneel.com/t/lock-selected-layer/112192/2 "2020-11-13T19:50:25Z")

</div>

Hi Piotr,  
I second this request and there should be a command and icon for it.  
For the time being it can be circumvented with a Vb or Python script since layer locked is a method. I don’t have time currently but maybe Mitch or someone else will help out.  
RM

---

<div class="post-metadata">

**Author:** ![Helvetosaur](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/helvetosaur/32/635974_2.png) [@Helvetosaur](https://discourse.mcneel.com/u/Helvetosaur)\
**Post date:** [November 13, 2020, 8:19pm UTC](https://discourse.mcneel.com/t/lock-selected-layer/112192/3 "2020-11-13T20:19:53Z")

</div>

Not sure I understand what you want here, lock the layer(s) of selected object(s)?

---

<div class="post-metadata">

**Author:** ![Piotr](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/piotr/32/635473_2.png) [@Piotr](https://discourse.mcneel.com/u/Piotr)\
**Post date:** [November 13, 2020, 8:31pm UTC](https://discourse.mcneel.com/t/lock-selected-layer/112192/4 "2020-11-13T20:31:13Z")

</div>

Simple.  
Pick an object to lock the layer it is ON.  
Similar to object’s layer ON or OFF.  
Imagine the following scenario:  
You receive the file with +200 layers (with some odd names), you pick the object,check it’s layer name in the properties panel and then you have to find the layer among +200 to lock it. Painful.

---

<div class="post-metadata">

**Author:** ![3dsynergy](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/3dsynergy/32/758178_2.png) [@3dsynergy](https://discourse.mcneel.com/u/3dsynergy)\
**Post date:** [November 13, 2020, 9:02pm UTC](https://discourse.mcneel.com/t/lock-selected-layer/112192/5 "2020-11-13T21:02:15Z")

</div>

Hi,  
I’m sure mines not as elegant as Mitch’s but you can paste this to an icon  
Select the object should lock that objects layer

noecho  
-RunScript (  
Option Explicit  
Call LayerLock  
Sub LayerLock()  
Dim strObject,arrLayers,strLayer

```
strObject = Rhino.GetObject("Selectobject")

If Not IsNull(strObject) Then
	strLayer = Rhino.ObjectLayer(strObject)
	Rhino.LayerLocked strLayer, True
End If

```

End Sub

Here’s the icon  
 ![LayerLock](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/e/1/e/e1e18d902a5b6930c6c8353209bbb1f1a11f44a4.png)

---

<div class="post-metadata">

**Author:** ![Piotr](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/piotr/32/635473_2.png) [@Piotr](https://discourse.mcneel.com/u/Piotr)\
**Post date:** [November 13, 2020, 9:06pm UTC](https://discourse.mcneel.com/t/lock-selected-layer/112192/6 "2020-11-13T21:06:47Z")

</div>

Chapeau bas  
Already added to the panel

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/2/c/d/2cdbba5cbc98f7f5f8068b5eec948468e37c3ff6.png)  
It would be nice to have a reverse action with same effect.  
At present: first icon, then object. It would be great for allowing also for first object, then icon.

---

<div class="post-metadata">

**Author:** ![Helvetosaur](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/helvetosaur/32/635974_2.png) [@Helvetosaur](https://discourse.mcneel.com/u/Helvetosaur)\
**Post date:** [November 13, 2020, 9:35pm UTC](https://discourse.mcneel.com/t/lock-selected-layer/112192/7 "2020-11-13T21:35:20Z")

</div>

What do you want to happen if a selected object is on the current layer?

---

<div class="post-metadata">

**Author:** ![Piotr](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/piotr/32/635473_2.png) [@Piotr](https://discourse.mcneel.com/u/Piotr)\
**Post date:** [November 13, 2020, 9:37pm UTC](https://discourse.mcneel.com/t/lock-selected-layer/112192/8 "2020-11-13T21:37:47Z")

</div>

Good question. Warning, probably, would be a good idea.

---

<div class="post-metadata">

**Author:** ![Helvetosaur](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/helvetosaur/32/635974_2.png) [@Helvetosaur](https://discourse.mcneel.com/u/Helvetosaur)\
**Post date:** [November 13, 2020, 9:41pm UTC](https://discourse.mcneel.com/t/lock-selected-layer/112192/9 "2020-11-13T21:41:06Z")

</div>

Try this one then:

Edit - sorry, small non-critical typo - please redownload.

[LockSelectedObjectLayers.py](https://discourse.mcneel.com/uploads/short-url/zvRJaaGTJGM6htYaXZ2BGmhULxx.py) (616 Bytes)

Note that this will probably not be reliable with blocks - that is to say it will lock the layer the block _instance_ is on, not the layers of the original objects that made up the block _definition_.

---

<div class="post-metadata">

**Author:** ![Piotr](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/piotr/32/635473_2.png) [@Piotr](https://discourse.mcneel.com/u/Piotr)\
**Post date:** [November 13, 2020, 9:49pm UTC](https://discourse.mcneel.com/t/lock-selected-layer/112192/10 "2020-11-13T21:49:56Z")

</div>

It worked bot got me bamboozled: see the hal-locked icon 🙂  
 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/7/3/7/73796f6367fd59015285ac05a56fe7e5459d38f0.png)

---

<div class="post-metadata">

**Author:** ![Helvetosaur](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/helvetosaur/32/635974_2.png) [@Helvetosaur](https://discourse.mcneel.com/u/Helvetosaur)\
**Post date:** [November 13, 2020, 9:51pm UTC](https://discourse.mcneel.com/t/lock-selected-layer/112192/11 "2020-11-13T21:51:50Z")

</div>

Yep, that’s to be expected if you have sublayers.

---

<div class="post-metadata">

**Author:** ![Piotr](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/piotr/32/635473_2.png) [@Piotr](https://discourse.mcneel.com/u/Piotr)\
**Post date:** [November 13, 2020, 9:54pm UTC](https://discourse.mcneel.com/t/lock-selected-layer/112192/12 "2020-11-13T21:54:22Z")

</div>

Are you sure? These two layers have the same parent ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/1/b/c/1bc4fcf9a6959391d8397adb74a9903230abb203.png)  
Not a big deal, just asking this question myself.

---

<div class="post-metadata">

**Author:** ![Helvetosaur](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/helvetosaur/32/635974_2.png) [@Helvetosaur](https://discourse.mcneel.com/u/Helvetosaur)\
**Post date:** [November 13, 2020, 9:57pm UTC](https://discourse.mcneel.com/t/lock-selected-layer/112192/13 "2020-11-13T21:57:39Z")

</div>

This is a bug or a quirk of locking sublayers via a python script as far as I know, it has been around for years and doesn’t look like it has been fixed for V7. There are similar problems with the half-lightbulb visibility icon IIRC.

---

<div class="post-metadata">

**Author:** ![Piotr](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/piotr/32/635473_2.png) [@Piotr](https://discourse.mcneel.com/u/Piotr)\
**Post date:** [November 13, 2020, 10:00pm UTC](https://discourse.mcneel.com/t/lock-selected-layer/112192/14 "2020-11-13T22:00:44Z")

</div>

> [@Helvetosaur](#):
>
> This is a bug

Something to push further…

---

<div class="post-metadata">

**Author:** ![Helvetosaur](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/helvetosaur/32/635974_2.png) [@Helvetosaur](https://discourse.mcneel.com/u/Helvetosaur)\
**Post date:** [November 13, 2020, 10:06pm UTC](https://discourse.mcneel.com/t/lock-selected-layer/112192/15 "2020-11-13T22:06:50Z")

</div>

> [@Piotr](#):
>
> Something to push further…

After a bug exists over 3 or more versions, I generally give up.

---

<div class="post-metadata">

**Author:** ![Helvetosaur](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/helvetosaur/32/635974_2.png) [@Helvetosaur](https://discourse.mcneel.com/u/Helvetosaur)\
**Post date:** [November 14, 2020, 9:10am UTC](https://discourse.mcneel.com/t/lock-selected-layer/112192/16 "2020-11-14T09:10:58Z")

</div>

I created a bugtrack item for this:  
[https://mcneel.myjetbrains.com/youtrack/issue/RH-61534](https://mcneel.myjetbrains.com/youtrack/issue/RH-61534)

OK, I did some more research and now I think I understand the problem. The start point was this Discourse thread:

> [@Set a sublayer to not visible in RhinoCommon](https://discourse.mcneel.com/t/set-a-sublayer-to-not-visible-in-rhinocommon/7383):
>
> Hello, How can I set a sublayer to IsVisible = false? I can set the value to false but the layer still visible when the command ends. I’ve tried to set “UnsetPersistentVisibility” and set the persistent visibility to false but without results. How can I do it? Thanks,

This touched on the previous problem of layer visibility which behaved in much the same way as locking does now in a script. It was fixed. I see the code for layerVisible() is different from layerLocked() in that for sublayers, it sets “persistent visibility”:

![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/3/8/7/3874b894e37c52da91d37404044ebea7953c04d6.png)

This is not the case for layer locking.

![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/3/0/6/3061670db0a62d3a4d8dce3d95635feacebe872d.png)

The method`Layer.SetPersistentLocking` does exist however.  
[https://developer.rhino3d.com/api/RhinoCommon/html/M\_Rhino\_DocObjects\_Layer\_SetPersistentLocking.htm](https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_DocObjects_Layer_SetPersistentLocking.htm)

So first, rhinoscriptsyntax needs to be tweaked so that it invokes that method and not simply `layer.IsLocked=True`.

However, I should be able to tweak the script above so that it does this already.

---

<div class="post-metadata">

**Author:** ![3dsynergy](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/3dsynergy/32/758178_2.png) [@3dsynergy](https://discourse.mcneel.com/u/3dsynergy)\
**Post date:** [November 14, 2020, 10:14am UTC](https://discourse.mcneel.com/t/lock-selected-layer/112192/17 "2020-11-14T10:14:46Z")

</div>

Hi Mitch,  
Nice work and I was hoping you would chime in.  
I was thinking that it would be nice to store the list of the layers that were locked then to unlock we wouldn’t have to search in the layer tab.

Forgive my rudimentary skills and it’s Vbscript but these scripts kind of hint at a way to deal with this idea. In LayerLockToAttributes I haven’t made the selection multi but just tried with one getobject and assigned it a data attribute. So if you Run the script select object that layer gets locked try the script again lock another layer etc and the data attributes are assigned.

Then from the MultiBoxUnlockLayers script it calls up a multi list box that lists the locked layers and one can unlock them easily also it lists the layers in selection order.

I don’t know if a data attribute is the best way to go but just thought I’d share it with you and if you can suggest any way to make these better or use any ideas into your own more advanced scripts please feel free.  
RM

[MultiBoxUnlockLayers\_001.rvb](https://discourse.mcneel.com/uploads/short-url/srLpybu2EDIIUxJWtHzDHVmG7Sw.rvb) (548 Bytes)  
[layerLockToLayerAttributes\_001.rvb](https://discourse.mcneel.com/uploads/short-url/63M4xJ1caVLwS99OXvJ55OcHgM1.rvb) (396 Bytes)

---

<div class="post-metadata">

**Author:** ![Helvetosaur](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/helvetosaur/32/635974_2.png) [@Helvetosaur](https://discourse.mcneel.com/u/Helvetosaur)\
**Post date:** [November 14, 2020, 10:17am UTC](https://discourse.mcneel.com/t/lock-selected-layer/112192/18 "2020-11-14T10:17:36Z")

</div>

> [@Helvetosaur](#):
>
> However, I should be able to tweak the script above so that it does this already.

Hmm, wrong, can’t seem to get it to work now. Maybe try later.

OK, I think I got it. Couldn’t get `layer.SetPersistentLocking()` to apply directly. However it seems to work if I set `layer.IsLocked=True` first, then set persistent. Don’t know if that’s really the correct procedure, but seems to work here. Below is a revised script to try. Let me know if it works for you.

[LockSelectedObjectLayers2.py](https://discourse.mcneel.com/uploads/short-url/98zMVZwh9FSJ5mcGVmGi3qtkklC.py) (1017 Bytes)

---

<div class="post-metadata">

**Author:** ![Helvetosaur](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/helvetosaur/32/635974_2.png) [@Helvetosaur](https://discourse.mcneel.com/u/Helvetosaur)\
**Post date:** [November 14, 2020, 10:40am UTC](https://discourse.mcneel.com/t/lock-selected-layer/112192/19 "2020-11-14T10:40:26Z")

</div>

> [@3dsynergy](#):
>
> Then from the MultiBoxUnlockLayers script it calls up a multi list box that lists the locked layers and one can unlock them easily also it lists the layers in selection order

I’m not sure you really need to add the locked state as attributes to the layer, as it already has the locked state in its base attributes. Isn’t what you want just a list of locked layers to choose from? That’s easily gotten by testing all layers and making a list of which are locked, then putting up a multi list box to choose. Or did I miss the point entirely?

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/1/8/2/1822e854c4c6805f12fc5ee7b720d9ef2628d226.png)

---

<div class="post-metadata">

**Author:** ![3dsynergy](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/3dsynergy/32/758178_2.png) [@3dsynergy](https://discourse.mcneel.com/u/3dsynergy)\
**Post date:** [November 14, 2020, 10:57am UTC](https://discourse.mcneel.com/t/lock-selected-layer/112192/20 "2020-11-14T10:57:31Z")

</div>

Hi Mitch,

> [@Helvetosaur](#):
>
> Or did I miss the point entirely?

Yes in way. I want to only list the layers that were locked by me locking them using the script not have to choose from “all” the layers. Since Piotr is locking layers by picking objects and without looking at the layer tab, if you have 100s of layers how would know which ones you locked by selection and which ones were locked due to other circumstance. So unless you had a list of those you locked by the script you wouldn’t know which ones to unlock and which ones to leave locked, thus my idea. Hope that makes sense.  
RM

[Next page](https://discourse.mcneel.com/t/lock-selected-layer/112192.md?page=2)
