Non-master or Background layers in DrawBot

I have a question about how to draw master layers, non-master, and background in Drawbot. Could anyone post a sample code?

Can the completeBezierPath method work for you? It’s a layer method, so I expect it should work on any master, non-master and background layer. It should return you the bezierPath that you can use to draw with drawPath(bezierPath).

Not tested, just from the top of my head, sth like this?!

BP = layer.completeBezierPath
fill(0.5, 1, 0, 1)
drawPath(BP) # drawbot function

Or is your question about how to access the named layers?

1 Like

Thanks! Actually, I don’t know how to find a font either. Glyphs.font doesn’t work, import GlyphsApp doesn’t either. What am I missing?

I think the problem is that in DrawBot, usually you deal with roboFab objects and those don’t allow access to other layers. But you can always use the Glyphs objects directly and the use the method mentioned by Mark.

‘Import GlyphsApp’ should work. I’ll have a look.

Sorry, import GlyphsApp works, but this code doesn’t.

import GlyphsApp
layer = Glyphs.font.selectedLayers[0]
BP = layer.completeBezierPath
fill(0.5, 1, 0, 1)
drawPath(BP)

Does it work if you use from GlyphsApp import * ? Here it works, still using Glyphs.font etc then.

You need to have from GlyphsApp import *. Then, that code will work.

[ Seems that Mark and I were typing around the same time. ]

Ah okay, now it does! I’m not sure why import GlyphsApp doesn’t (is that for a legit reason?), but thanks guys!

If you import GlyphsApp, you will have to prefix all Glyphs objects with GlyphsApp., so, GlyphsApp.Glyphs.font would have worked, I suppose.

The reason is exactly what @mekkablue wrote. It’s how module references are handled in Python. Yes, GlyphsApp.Glyphs.font would have worked.

import GlyphsApp
font = GlyphsApp.Glyphs.font

and

from GlyphsApp import *
font = Glyphs.font

and

from GlyphsApp import Glyphs
font = Glyphs.font

are equivalent for referencing the Glyphs object.

Hmm, that’s interesting. In other Python scripts normally you would import GlyphsApp and immediately following statements like f=Glyphs.font work. I wonder why I don’t need to do from GlyphsApp import * in those cases.

Anyway, I can finally go bananas with Drawbot. Thanks!

I wonder that, too. Anyway, enjoy :smiley:

The python environment in Glyphs gets some properties set that enable some shortcuts.