Lock selected layer

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.

1 Like

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.

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

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.

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

-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

Chapeau bas
Already added to the panel

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.

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

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

Try this one then:

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

LockSelectedObjectLayers.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.

It worked bot got me bamboozled: see the hal-locked icon :slight_smile:

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

Are you sure? These two layers have the same parentimage
Not a big deal, just asking this question myself.

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.

Something to push further…

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

1 Like

I created a bugtrack item for this:

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

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”:


This is not the case for layer locking.


The methodLayer.SetPersistentLocking does exist however.

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.

1 Like

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.

MultiBoxUnlockLayers_001.rvb (548 Bytes)
layerLockToLayerAttributes_001.rvb (396 Bytes)

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 (1017 Bytes)

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?

Hi Mitch,

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.