Can I toggle layer visibility in script?
StephenNixon last edited by gferreira
Can I toggle layer visibility in script? It seems possible via the
setDisplayOptionmethod. By following this with
getDisplayOptionfor each layer, it seems like it should be working. However, my open glyph windows don't update.
I think maybe I need to use
changed(), or something similar?
# Hide other layers for all open fonts currentLayerName = CurrentLayer().name for f in AllFonts(): for layer in f.layers: if layer.name != currentLayerName: layer.setDisplayOption('all', False) # do I need something like this? layer.changed()
Any help is appreciated. Thanks!
this should work:
currentLayerName = CurrentLayer().name for f in AllFonts(): for layer in f.layers: if layer.name != currentLayerName: layer.setDisplayOption('Fill', False) layer.setDisplayOption('Stroke', True) layer.setDisplayOption('Points', True) layer.setDisplayOption('Coordinates', False) layer.setDisplayOption('all', True) # do I need something like this? layer.changed()
There is an ambiguity in the method names and will change it in the next updates:
getDisplayOptionreturns now a dict
setDisplayOptionrequires a key, value (this must actually be a dict with multiple values...)
connor last edited by
There is also this great script that @andyclymer wrote: https://github.com/andyclymer/RoboFont-StartupScripts/blob/master/Hotkey-ShowHideLayers.py
StephenNixon last edited by
Thanks, @frederik! Unfortunately, this doesn't seem to be working for me just yet.
Just to clarify, my overall problem is this: I have 12+ masters I want to edit at the same time. Sometimes, I want to view background layers, to see prior iterations, etc. Other times (like right now), I want to hide those layers so they don't distract me as I make the foreground layer compatible. I don't want to go through every one of the masters and click off the layers, because that would be really tedious, and something I'd likely have to do quite a few times in the future.
Is there some reason that the layer display options wouldn't be working to hide non-foreground layers? Do I need to use something like
layer.changed()in my script, to make the settings take effect?
Note: I'm in
Version 3.3b (build 1906031450), if that makes a difference.
StephenNixon last edited by
I've been able to slightly modify Andy's script to work for what I need.
I've made it toggle background points along with strokes, across all open fonts.
Thanks for pointing me to it, Connor! It's even better having it tied to a hotkey.
(Overall, I think maybe my main problem before was missing
f.getLayer(layerName)in front of
from mojo.UI import SetCurrentLayerByName from mojo.events import addObserver, removeObserver class ShowHideLayers(): """ Startup Script: Assigns the "h" key to show/hide layer outlines across all open fonts. -- Modified from https://github.com/andyclymer/RoboFont-StartupScripts """ def __init__(self): addObserver(self, "keyDown", "keyDown") def showHideOption(self, displayOptionKey, currentDisplayOptionValue): af = AllFonts() for f in af: for layerName in f.layerOrder: if not layerName == "foreground": f.getLayer(layerName).setDisplayOption(displayOptionKey, not currentDisplayOptionValue) def keyDown(self, info): event = info["event"] characters = event.characters() modifierFlags = event.modifierFlags() if characters == "h": f = CurrentFont() if len(f.layerOrder) > 1: nextLayer = f.layerOrder # Get the current display status for the first non-foreground layer currentDisplayOption = f.getLayer(nextLayer).getDisplayOption()["Stroke"] # show/hide stroke and points self.showHideOption("Stroke", currentDisplayOption) self.showHideOption("Points", currentDisplayOption) ShowHideLayers()
and there is a silly typo in the toggling the
alloption... will be fixed in the next update