Hi
i wanted to wrote an script, i used offset curve filter in script for a layer before(like OffsetCurveFilter.offsetLayer_...
). for current case i should iterating this filter over any path separately. i saw offsetCurveFilter.offsetPath_...
here but i can’t use it like i used for offset layer before. please give an example.
What happens? Do you get an error message?
nothing happens. when i change parameters to invalid inputs, nothing happens neither.
(Glyphs version: 3.3 (3323))
Can you show you code?
yes, this is my code:
import objc
from AppKit import NSButtLineCapStyle
OffsetCurveFilter = objc.lookUpClass("GlyphsFilterOffsetCurve")
font = Glyphs.fonts[0]
font.disableUpdateInterface()
for glyph in font.glyphs:
for layer in glyph.layers:
for path in layer.paths:
OffsetCurveFilter.offsetPath_offsetX_offsetY_makeStroke_position_objects_capStyleStart_capStyleEnd_(path, 100, 100, False, 0.5, False, 1, 1)
font.enableUpdateInterface()
Then read the post you linked too above. It has the answer.
sorry to disappoint you
i tried to solve the problem but i couldn’t figure out how.
i realized that the offsetCurveFilter.offsetPath_...
returns an objective-c object which need to be converted.
i changed the code:
import objc
from AppKit import NSButtLineCapStyle
OffsetCurveFilter = objc.lookUpClass("GlyphsFilterOffsetCurve")
font = Glyphs.fonts[0]
font.disableUpdateInterface()
for glyph in font.glyphs:
for layer in glyph.layers:
for path in layer.paths:
layer.paths.append(OffsetCurveFilter.offsetPath_offsetX_offsetY_makeStroke_position_objects_capStyleStart_capStyleEnd_(path, 100, 100, False, 0.5, False, 1, 1))
font.enableUpdateInterface()
and got this error:
Traceback (most recent call last):
File "<macro panel>", line 11
File "GlyphsApp/GlyphsApp/__init__.py", line 619, in <lambda>
ValueError: NSInvalidArgumentException - -[__NSArrayM setParent:]: unrecognized selector sent to instance 0x60000416ea30
As described in the post you linked, the returned value type is NSArray, which is a list. You can’t append that to GSLayer.paths.
Iterate over the items in the returned array and append each one to the layer paths.
filter_result = OffsetCurveFilter.offsetPathblabla_()
for transformed_path in filter_result:
layer.paths.append(transformed_path)
And your logic is flawed. In your code example, you’re iterating over layer.paths and then appending the NSArray to layer.paths for every path in the layer. That isn’t what you want.
thank you. I tried some complicated ways and didn’t know it was this simple :))
yes, the loop over paths increase their numbers and never end. i add a PathNumber
check condition and it working for me now:
import objc
from AppKit import NSButtLineCapStyle
OffsetCurveFilter = objc.lookUpClass("GlyphsFilterOffsetCurve")
font = Glyphs.fonts[0]
font.disableUpdateInterface()
for glyph in font.glyphs:
for layer in glyph.layers:
PathNumber = len(layer.paths)
for path in layer.paths:
if PathNumber > 0:
filter_result = OffsetCurveFilter.offsetPath_offsetX_offsetY_makeStroke_position_objects_capStyleStart_capStyleEnd_(path, 100, 100, False, 0.5, False, 1, 1)
for transformed_path in filter_result:
layer.paths.append(transformed_path)
PathNumber = PathNumber - 1
font.enableUpdateInterface()
thank you.
While iterating layer.paths
, you can change that property. And even if that isn’t crashing right away, the newly added paths are offset again and again.
And in Glyphs 3, you can’t add to the paths. You need to use layer.shapes
.
So while iterating, you need to store the result in a temporary list and either append (in python it would be: layer.shapes.extend(newPaths)
that to layer.shapes or replace it (layer.shapes = newPaths
).
thank you