Robofab vs Glyphs.app

I’m having some issues with RoboFab scripting, so I’m trying to use Glyphs objects instead. More specifically, I can’t cycle through components or anchors through RoboFab (for one script I want to output all the components for each glyph to double-check that I used the right components where there are variations, say with accents where I have regular, UC, narrow and UC narrow versions; the other one would look at each glyph’s anchors and add TOP or BOTTOM anchors if they are missing). The scripts run perfectly on RoboFont, so I figured it’s a Glyphs-RoboFab issue and decided to bite the bullet and learn to use the Glyphs model.

My question is whether there are “current” objects. Instead of having to specify a layer number (or font or master, etc), could I just say CurrentLayer? Or is there a “selection” object that would go through the glyphs in the selection (I can do it with RoboFab, but can’t seem to understand it with Glyphs).

Also, not 100% sure what’s the difference between layers and masters. And while I’m at it, how can I access the background layer through scripting?

Thanks

Could you send me the script that is not working?

there is Font.selectedLayers and Font.selectedFontMaster

You can do stuff like this:

for layer in Font.selectedLayers:
print layer

or

masterID = Font.selectedFontMaster.id
for glyph in Font.glyphs:
layer = glyph.layers[masterID]
print layer

the background is just
layer.background

it is another layer…

did you read the python documentation?

And the scripts from mekkablue are a good reference.

Sorry for the double-dipping. I thought it was a RoboFab issue and posted on the other forum and when I realized it wasn’t I posted here��"and you had already replied when I went to delete the other post.

Downloaded the latest objectsGS and the anchors are now working, but the components still are not. These are the three scripts in question:

http://projects.bernard-o.com/SCRIPTS/APPEND_ANCHOR.py

http://projects.bernard-o.com/SCRIPTS/PRINT_COMPONENTS_GLYPHS.py

http://projects.bernard-o.com/SCRIPTS/PRINT_COMPONENTS.py

First and second scripts work on Glyphs (thanks for fixing the objectsGS.py file). Third script is still not working. Here are some screen grabs.

I did look at the documentation, but a search for “current” yielded no results. It’s a bit technical and I’m still figuring out the hierarchy.

Thanks.

Why do you want a script to output component names? This is already built into the app. Go to the font tab, switch to list view, and make sure the components column is on.

And if you still want a script to do that, must it be with RoboFab? It’s easy with plain vanilla Glyphs objects.

Yeah, in my original question I mentioned I solved it with Glyphs objects and my question was specifically about Glyphs objects (how to use the “current” elements). But Georg asked me to send the scripts and he fixed objectsGS for the anchors object, so I posted the RoboFab version. I appreciate that Glyphs has so many built-in tools, but my point in learning all this is to be able to build new tools.

At this point I’ve realized I’d be better served by learning the Glyphs object but RoboFab support was definitely a big selling point.

The list view is very helpful. Good to see it can be printed too.

This is how I would write the script:
http://pastebin.com/pjNXfMMB

Better to use a list comprehension than to just hang plusses at the end of each glyph name. The current font is Glyphs.font, the currently active layers of selected glyphs are Glyphs.font.selectedLayers, etc. I suppose you know this site already:
http://docu.glyphsapp.com

Perhaps you want to peek into my GitHub repository or Georg’s to get an idea.
https://github.com/mekkablue/Glyphs-Scripts
https://github.com/schriftgestalt/Glyphs-Scripts

That’s awesome! Still learning, so this is kinda advanced to me, but cool to know. Wrapping my head around the last print statement, but I just used the way you did the listOfComponents to save some lines in another script.

Quite familiar with docu.glyphsapp.com. As much as I love the handbook, I’m still learning to navigate this resource.

Thanks for your help. Can you recommend any resources for learning more advanced Python? I took a couple of basic workshops, but would love to learn more.

I keep the Python Pocket Reference under my pillow all the time.

And thanks to the magic of Kindle, it’ll be under my pillow tonight. Thanks.

Hey Mekka, been reading the book (thanks for the suggestion) and now that I understand your script I’m wondering what’s the advantage of using %s over writing it like this? or is it just a coding style choice?

print thisLayer.parent.name + " = " + " + ".join( listOfComponents )

B

It is more modular and thus much easier to change, re-use or fix at a later time. Imagine you want to change the structure of the sentence, or add more string variables. Besides, I do believe it creates easier-to-read code.

Gotcha! Thanks.