Locking Layers for upcoming versions

There is no lock icon in the Layers palette, but if you find yourself frequently needing to lock/unlock all paths and components on a layer, you can try the following scripts:

Lock all Shapes in Selected Layers:

for layer in Font.selectedLayers:
	for shape in layer.shapes:
		shape.locked = True

Unlock all Shapes in Selected Layers:

for layer in Font.selectedLayers:
	for shape in layer.shapes:
		shape.locked = False
1 Like

Thanks Florian! this is a good first step.

A more efficient way would be to incorporate that code into a single script which would do one action or the other depending on the current state. I wish I could do it but writing code isn’t something I can do.

The following script toggles between locking and unlocking all shapes in all selected layers:

Lock/Unlock all Shapes in Selected Layers:

for layer in Font.selectedLayers:
	for shape in layer.shapes:
		shape.locked = not shape.locked

Note that, if a layer contains a manually locked path and a path that is not locked, they will not end up both locked or unlocked but switch individually.

Doesn’t work for me. If the Layer isn’t locked to begin with then that code doesn’t do anything. If any glyph is manually locked, it does not unlock it except flash a message in the Preview Panel, “Undo Set Lock”. In the Macro Panel, it doesn’t return any results.

Anyway, I’m hoping for a standalone script that doesn’t depend on pasting code into the Macro Panel.

The Macro Panel should not return or output anything. The only thing that changes is that all paths are locked and unlocked.

Any macro can be saved as a script:

  • Create a text file file and place a line # MenuTitle: SOME TITLE at the top where SOME TITLE is the name of the script that will show up in the scripts menu.
  • Place the script in Glyphs’ Scripts folder (on in a subfolder therein).
  • The file can have any name ending in .py (it is best practice to name the file after the script).
  • Click on the Scripts menu, hold down the Option key, and choose Reload Scripts to show the newly created script.

It does not work for me. I tried it also with all Plugins disabled, same result.
I noticed in your video that you don’t have multiple layers or apparently any outlines. How can you be sure it works?

The file in the video is just to show the script saving process, I don’t run the script in the video.

The code is short, so there is not a lot to get wrong. For all selected layer, all path/component that are lock are unlocked and all that are unlocked are locked.

Have you any layers selected? If you are in Edit View, the current layer also counts as “selected”.

Georg,
Put the uncompressed folder into Scripts Folder and reload scripts
Is necessary select the glyphs that you like Lock or Unlock.
I think that is possible apply to whole glyphs without select all but don’t know how to do with code. :slight_smile: I’m a simple type-designer
Lock-Unlock.zip (2.4 KB)

@FlorianPircher – Font View or Edit View, there isn’t any difference. I tried selecting layers in the panel at the right as well as the top-left icons; no difference.

@etunni – Nothing locks, whether anything is selected or not.

I am beginning to suspect OS differences. I’m still on 10.13.6, and cannot upgrade past that because I’ll lose all Nvidia support for my GPU. I’m hoping November will put an end to my wait.

Problem solved! Simple, too. Not an OS issue.

I was testing locking by opening a glyph in the supposed locked layer and doing Cmd-A, which selects all nodes and they can be moved. However, trying to select any nodes other than All, the Layer is locked.

So both scripts worked, although @etunni’s Unlock script only unlocks one glyph.

::EDIT:: Now that all this has been done it occurs to me the method involved is not what originally was asked for. As @etunni’s graphic at the top of the thread shows, the goal was to lock the layer, thus preventing access to the Layer, and that is really what is preferred.

Perhaps could be possible with a custom parameter like disable master but in this case lock master.

Did we speak about why you like to do that? What should the locking prevent?

Avoid working on a finished layer.
The short script published by Florian fulfills the function.

Florian’s script locks the glyphs, not the layers, which is what the original request was – to prevent editing access to a Layer, as illustrated by your graphic at the top of this thread

Locking the Layer would still be the ideal because even with the glyph locked using the script, when a Cmd-A is done on an outline on the “locked layer” many actions can still be performed on the entire outline.

There are differences between using the script and using the Lock property on the contextual menu.

  1. The script doesn’t display the Lock icon.
  2. The script will not unlock a glyph which was locked using the Lock property.

There may be other differences I didn’t think to check, but the script is still very useful. Thanks to @Florian for providing it.

  • Locking a glyph (that is, locking all layers of a glyph) is a feature that is included in Glyphs.
  • Locking an individual path or component is also a feature of Glyphs.
  • My scripts lock/unlock all paths/components on the selected layers.

It appears what you want is locking masters so that locking a master would lock all layers belonging to that master. Is that correct?

Yes, as originally requested by @etunni.

@etunni
Here is a script I put together based on the code in this thread, which checks the Lock state and switches it if anyone wants to use it.

It only works on selected glyphs, so in Font View you can select individual cells or select everything, but in Edit View, only the glyph you have open will be affected by this script. It outputs a message in the Macro Panel giving the Layer name and Lock state.

Note: If anyone thinks the code could be better, I’m sure it could be. I have not had a programming class since the early 90’s so can’t be considered proficient in coding.

[[ File removed because Georg’s code below is much better. ]]

1 Like

To make it more stable, I would look at the first shape and then set all other look states to the opposite if is.

for layer in Font.selectedLayers:
	if len(layer.shapes) == 0:
		continue
	looked = layer.shapes[0].locked
	for shape in layer.shapes:
		if shape.locked == looked:
			shape.locked = not looked
1 Like

Thank you for improving on the code. There is always a more efficient way.