I need to create UFOs and would like to find any instance of these kinds of corners to convert them before exporting, is this possible with a script?
You can’t detect them from a script. You could run all paths throu a pen. The path.draw() method will remove them (and will apply caps and corners).
Can it remove only outside corners and not the inside ones?
Yes. It gives back what is drawn in black in edit mode. It removed the gray parts.
Which pen should I use?
from fontTools.pens.basePen import BasePen Font = Glyphs.font FontMaster = Font.selectedFontMaster selectedLayers = Font.selectedLayers for thisLayer in Font.selectedLayers: for thisPath in thisLayer.paths: thisPath.draw(BasePen)
Gives me this error:
Traceback (most recent call last): File "<string>", line 14, in <module> File "GlyphsApp/__init__.py", line 5483, in DrawPathWithPen TypeError: unbound method moveTo() must be called with BasePen instance as first argument (got NSPoint instance instead)
Does this help?
from GlyphsApp import GSPathPen layer = Font.selectedLayers pen = GSPathPen.alloc().init() layer.drawInPen_(pen) print pen.layer().paths
If your example, you passed the class of the pen as an argument. You would need to instantiate it, first. But the Base objects should not be used. You need to pick a subclass that actually implements something.
Modifying while looping
thanks georg! this works, however i get this error:
Glyphs.clearLog() from GlyphsApp import GSPathPen thisLayer = Font.selectedLayers for eachPath in thisLayer.paths: newPath = eachPath.copy() pen = GSPathPen.alloc().init() thisLayer.drawInPen_(pen) newPath = pen.layer().paths newPath = newPath thisLayer.removePath_(eachPath) thisLayer.addPath_(newPath)
Traceback (most recent call last): File "<string>", line 5, in <module> File "GlyphsApp/__init__.py", line 135, in __iter__ File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC/objc/_convenience.py", line 589, in enumeratorGenerator yield container_unwrap(anEnumerator.nextObject(), StopIteration) objc.error: NSGenericException - *** Collection <__NSArrayM: 0x7fb731d18cc0> was mutated while being enumerated.
The traceback says it: you remove items that you actually iterate over. this is not possible. either iterate in reversed order, or do multiple iterations.
Got it thanks~!
Glyphs.clearLog() from GlyphsApp import GSPathPen thisLayer = Font.selectedLayers layerPaths = [l for l in thisLayer.paths] thisLayer.paths =  for eachPath in layerPaths: pen = GSPathPen.alloc().init() eachPath.drawInPen_(pen) eachPath = pen.layer().paths eachPath = eachPath thisLayer.addPath_(eachPath)
Open outer corners - is there a script to remove them?
Hey this script suddenly converts smooth points into corner points…? anyway to stop this.
Simply run the
cleanUpPaths() method of the layer afterwards.
Is there a method similar to
cleanUpPaths which doesn’t ever remove nodes?
What is the point of cleaning up paths of you are not removing nodes? Can you give an example of what you want to do?
There is a
checkConnections() on GSLayer and GSPath.
The point of not removing nodes is when you have overlapping nodes for interpolation purposes.
I have the same issue where I need to clean up paths without removing stacked nodes.