Running HatchOutlineFilter programatically

So I found a way to run the HatchOutlineFilter using python, but when I run runFilterWithLayer_error_ it shows the dialog and I’m not sure which function to run to just get the Paths/Shapes. Ideally I would like to run it on a copy of a layer and then extract the shapes for that layer, but here it seems to use the background layer for storing the original shape and layer[0] to show the outline.

I tried looking around using the Python methods dir, signature, the method reporter by mekkablue and the Frameworks-directory in glyphs, but the HatchOutlineFilter is surprisingly opaque. It looks like it’s a builtin Glyphs filter without much info on how it works internally.

Maybe someone else knows a little more on how to use the HatchOutlineFilter using Python?

Have you tried the method reporter script from mekkablue?

Yes.

The mekkablue script doesn’t seem to go that far beyond the Glyphs API description.
There’s some loose coupling by using NSClassFromString that makes the code pretty opaque, which is why I’m having a bit of trouble triggering the HatchOutlineFilter programatically.

HatchOutlineFilter = NSClassFromString("HatchOutlineFilter")
HatchOutlineFilter.hatchLayer_origin_stepWidth_angle_offset_checkSelection_shadowLayer_(Layer, (10, 10), 20, 20, 5, False, None)

Thank you!
Do you know the method signature as well?
I.e. what the parameters are?

Was this available looking through the header-files in the Frameworks-directory or mekkablue or did you have to look through the source code somehow?

I was about to look into how to solve this by doing the hatchOutline manually. It looks like there’s a method for finding intersections between two shapes, and if I create a large set of hatches spanning the entire glyph I could do that for each line segment, but my programmer brain goes into analysis paralysis when I’m convinced there’s some smarter and more elegant way of doing those things.

The arguments in the sample code match with parts of the method name. Each argument goes where an underscore is. That should give you an idea.

Yes, I had to go through the source code.

What version of Glyphs do you have?

Glyphs 3

Try the latest beta please. Go to Glyphs > Preferences > Updates, activate both checkboxes and press the Update button.

same issue, checked “show cutting edge versions” and updated.

There, finally worked, thanks.

Is there some way I can do the same with the Extrude filter? I found out how to instantiate the effect, but I don’t know the method signature, I tried guessing, but that doesn’t seem to be the correct one.

	for myGlyph in Font.selection:
		layer = copy.deepcopy(myGlyph.layers[0])
		ExtrudeFilter = NSClassFromString("Extrude")
		ExtrudeFilter.extrudeLayer_offset_angle_dontSubtract_(layer, 0, 45, False)

The filters are signally different and more or less easy to call from scripts. I’ll see if I can improv his.

ExtrudeFilter = NSClassFromString("Extrude").new()
ExtrudeFilter.setOffset_(0)
ExtrudeFilter.setAngle_(45)

for myGlyph in Font.selection:
	layer = copy.deepcopy(myGlyph.layers[0])
	ExtrudeFilter.processLayer_(layer)

I refactored a bit to make it easier for scripts like this. So in the next update you can use this:

ExtrudeFilter = NSClassFromString("Extrude")

for myGlyph in Font.selection:
	layer = copy.deepcopy(myGlyph.layers[0])
	ExtrudeFilter.extrudeLayer_offset_angle_subtract_(layer, 0, 45, True)
1 Like