Apply offset curve to specific glyph layers via scripting

This does what I want it to with the glyphs I pass to it (puts a fattened version in the second layer), but it also runs the offset curve filter on all other glyphs. What am I doing wrong?

def filter(name):
    for filter in Glyphs.filters:
	    if filter.__class__.__name__ == name:
		    return filter

def setUpBase(baseGlyph):
  #replace 2nd layer with copy of first
  preserveLayer = font.glyphs[baseGlyph].layers[0].copy()
  print("preserve layer:", preserveLayer)
  thisLayer = font.glyphs[baseGlyph].layers[font.masters[1].id]
  offsetCurveFilter = filter('GlyphsFilterOffsetCurve')
  offsetCurveFilter.processFont_withArguments_(font, ['GlyphsFilterOffsetCurve', '100', '100', '0', '0.5', 'include: %s' %baseGlyph])
  outlineLayer = font.glyphs[baseGlyph].layers[0].copy()
  outlineLayer.layerId = font.masters[1].id
  font.glyphs[baseGlyph].layers[font.masters[1].id] = outlineLayer
  font.glyphs[baseGlyph].layers[0] = preserveLayer

Don’t run the offsetcurve filter on then full font. There is functions to run it on single layers directly.

I’d tried a reference to a layer (font.glyphs[baseGlyph].layers[0]) in place of “font” in that line but with no luck. NSInvalidArgumentException

Script code for Offset curve - #4 by GeorgSeifert

Ugh, I’m still so confused. What do I do with that code you linked to?

The second post in that thread has a full script sample. Only the detail of the API has changed since I posted it.
This should help with understanding my last post: An introduction to PyObjC — PyObjC - the Python to Objective-C bridge

1 Like

These at least don’t return errors, but they still don’t do anything to the paths:

offsetCurveFilter.offsetPath_offsetX_offsetY_makeStroke_position_(path, 100, 100, 0, 0.5)

offsetCurveFilter.offsetPath_offsetX_offsetY_makeStroke_position_objects_capStyleStart_capStyleEnd_(path, 100, 100, False, 0.5, False, 1, 1)

(Both are in a for path in Layer.paths: loop, and are preceded by offsetCurveFilter = objc.lookUpClass("GlyphsFilterOffsetCurve") and from AppKit import NSButtLineCapStyle )

Am I getting closer?

Check the return values.

Do you mean the format that each argument should return?

Does “objects” refer to the “keep compatible” box? what is an appropriate value for mutable array? for the buttlinecapstyle?

Do I need all the arguments or just ones that aren’t default?

I barely know what I’m doing with scripting so this is all a little over my head.

No, check what the method call is returning. It is not changing the path you put in, it returned the offsetted result.

It returns an “NSArrayM,” so how do I make that into a path or a layer?

It is a list of paths. NSArray is the objectiveC list.

1 Like