# How to detect an outside open corner

**URL:** <https://forum.glyphsapp.com/t/how-to-detect-an-outside-open-corner/4117>\
**Category:** Scripting\
**Created:** [March 24, 2016, 12:18pm UTC](https://forum.glyphsapp.com/t/how-to-detect-an-outside-open-corner/4117 "2016-03-24T12:18:05Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![oneweioranother](https://forum.glyphsapp.com/user_avatar/forum.glyphsapp.com/oneweioranother/32/273_2.png) [@oneweioranother](https://forum.glyphsapp.com/u/oneweioranother)\
**Post date:** [March 24, 2016, 12:18pm UTC](https://forum.glyphsapp.com/t/how-to-detect-an-outside-open-corner/4117/1 "2016-03-24T12:18:05Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![GeorgSeifert](https://forum.glyphsapp.com/user_avatar/forum.glyphsapp.com/georgseifert/32/259_2.png) [@GeorgSeifert](https://forum.glyphsapp.com/u/GeorgSeifert)\
**Post date:** [March 24, 2016, 12:34pm UTC](https://forum.glyphsapp.com/t/how-to-detect-an-outside-open-corner/4117/3 "2016-03-24T12:34:49Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![oneweioranother](https://forum.glyphsapp.com/user_avatar/forum.glyphsapp.com/oneweioranother/32/273_2.png) [@oneweioranother](https://forum.glyphsapp.com/u/oneweioranother)\
**Post date:** [March 24, 2016, 1:23pm UTC](https://forum.glyphsapp.com/t/how-to-detect-an-outside-open-corner/4117/4 "2016-03-24T13:23:01Z")

</div>

Can it remove only outside corners and not the inside ones?

---

<div class="post-metadata">

**Author:** ![GeorgSeifert](https://forum.glyphsapp.com/user_avatar/forum.glyphsapp.com/georgseifert/32/259_2.png) [@GeorgSeifert](https://forum.glyphsapp.com/u/GeorgSeifert)\
**Post date:** [March 24, 2016, 2:32pm UTC](https://forum.glyphsapp.com/t/how-to-detect-an-outside-open-corner/4117/5 "2016-03-24T14:32:16Z")

</div>

Yes. It gives back what is drawn in black in edit mode. It removed the gray parts.

---

<div class="post-metadata">

**Author:** ![oneweioranother](https://forum.glyphsapp.com/user_avatar/forum.glyphsapp.com/oneweioranother/32/273_2.png) [@oneweioranother](https://forum.glyphsapp.com/u/oneweioranother)\
**Post date:** [March 25, 2016, 2:32pm UTC](https://forum.glyphsapp.com/t/how-to-detect-an-outside-open-corner/4117/6 "2016-03-25T14:32:20Z")

</div>

Which pen should I use?

i.e.

```auto
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:

```auto
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)

```

---

<div class="post-metadata">

**Author:** ![oneweioranother](https://forum.glyphsapp.com/user_avatar/forum.glyphsapp.com/oneweioranother/32/273_2.png) [@oneweioranother](https://forum.glyphsapp.com/u/oneweioranother)\
**Post date:** [May 15, 2016, 3:11pm UTC](https://forum.glyphsapp.com/t/how-to-detect-an-outside-open-corner/4117/7 "2016-05-15T15:11:11Z")

</div>

bump please

---

<div class="post-metadata">

**Author:** ![GeorgSeifert](https://forum.glyphsapp.com/user_avatar/forum.glyphsapp.com/georgseifert/32/259_2.png) [@GeorgSeifert](https://forum.glyphsapp.com/u/GeorgSeifert)\
**Post date:** [May 16, 2016, 9:50am UTC](https://forum.glyphsapp.com/t/how-to-detect-an-outside-open-corner/4117/8 "2016-05-16T09:50:56Z")

</div>

Does this help?

```auto
from GlyphsApp import GSPathPen
layer = Font.selectedLayers[0]
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.

---

<div class="post-metadata">

**Author:** ![oneweioranother](https://forum.glyphsapp.com/user_avatar/forum.glyphsapp.com/oneweioranother/32/273_2.png) [@oneweioranother](https://forum.glyphsapp.com/u/oneweioranother)\
**Post date:** [May 16, 2016, 11:23am UTC](https://forum.glyphsapp.com/t/how-to-detect-an-outside-open-corner/4117/9 "2016-05-16T11:23:12Z")

</div>

thanks georg! this works, however i get this error:  
code:

```auto
Glyphs.clearLog()
from GlyphsApp import GSPathPen
thisLayer = Font.selectedLayers[0]

for eachPath in thisLayer.paths:
	
	newPath = eachPath.copy()
	pen = GSPathPen.alloc().init()
	thisLayer.drawInPen_(pen)
	newPath = pen.layer().paths
	newPath = newPath[0]

	thisLayer.removePath_(eachPath)
	thisLayer.addPath_(newPath)

```

error:

```auto
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.

```

---

<div class="post-metadata">

**Author:** ![Mark](https://forum.glyphsapp.com/user_avatar/forum.glyphsapp.com/mark/32/20784_2.png) [@Mark](https://forum.glyphsapp.com/u/Mark)\
**Post date:** [May 16, 2016, 1:04pm UTC](https://forum.glyphsapp.com/t/how-to-detect-an-outside-open-corner/4117/10 "2016-05-16T13:04:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![oneweioranother](https://forum.glyphsapp.com/user_avatar/forum.glyphsapp.com/oneweioranother/32/273_2.png) [@oneweioranother](https://forum.glyphsapp.com/u/oneweioranother)\
**Post date:** [May 16, 2016, 1:20pm UTC](https://forum.glyphsapp.com/t/how-to-detect-an-outside-open-corner/4117/11 "2016-05-16T13:20:38Z")

</div>

Got it thanks~!

```auto
Glyphs.clearLog()
from GlyphsApp import GSPathPen
thisLayer = Font.selectedLayers[0]

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[0]
	thisLayer.addPath_(eachPath)

```

---

<div class="post-metadata">

**Author:** ![oneweioranother](https://forum.glyphsapp.com/user_avatar/forum.glyphsapp.com/oneweioranother/32/273_2.png) [@oneweioranother](https://forum.glyphsapp.com/u/oneweioranother)\
**Post date:** [December 20, 2017, 3:36pm UTC](https://forum.glyphsapp.com/t/how-to-detect-an-outside-open-corner/4117/12 "2017-12-20T15:36:29Z")

</div>

Hey this script suddenly converts smooth points into corner points…? anyway to stop this.  
thanks!

---

<div class="post-metadata">

**Author:** ![mekkablue](https://forum.glyphsapp.com/user_avatar/forum.glyphsapp.com/mekkablue/32/23_2.png) [@mekkablue](https://forum.glyphsapp.com/u/mekkablue)\
**Post date:** [December 20, 2017, 10:52pm UTC](https://forum.glyphsapp.com/t/how-to-detect-an-outside-open-corner/4117/13 "2017-12-20T22:52:45Z")

</div>

Simply run the `cleanUpPaths()` method of the layer afterwards.

---

<div class="post-metadata">

**Author:** ![RobertJanes](https://forum.glyphsapp.com/user_avatar/forum.glyphsapp.com/robertjanes/32/3982_2.png) [@RobertJanes](https://forum.glyphsapp.com/u/RobertJanes)\
**Post date:** [March 1, 2019, 9:41am UTC](https://forum.glyphsapp.com/t/how-to-detect-an-outside-open-corner/4117/14 "2019-03-01T09:41:34Z")

</div>

Is there a method similar to `cleanUpPaths` which doesn’t ever remove nodes?

---

<div class="post-metadata">

**Author:** ![mekkablue](https://forum.glyphsapp.com/user_avatar/forum.glyphsapp.com/mekkablue/32/23_2.png) [@mekkablue](https://forum.glyphsapp.com/u/mekkablue)\
**Post date:** [March 1, 2019, 7:50pm UTC](https://forum.glyphsapp.com/t/how-to-detect-an-outside-open-corner/4117/15 "2019-03-01T19:50:32Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![GeorgSeifert](https://forum.glyphsapp.com/user_avatar/forum.glyphsapp.com/georgseifert/32/259_2.png) [@GeorgSeifert](https://forum.glyphsapp.com/u/GeorgSeifert)\
**Post date:** [March 1, 2019, 7:52pm UTC](https://forum.glyphsapp.com/t/how-to-detect-an-outside-open-corner/4117/16 "2019-03-01T19:52:18Z")

</div>

There is a `checkConnections()` on GSLayer and GSPath.

---

<div class="post-metadata">

**Author:** ![oneweioranother](https://forum.glyphsapp.com/user_avatar/forum.glyphsapp.com/oneweioranother/32/273_2.png) [@oneweioranother](https://forum.glyphsapp.com/u/oneweioranother)\
**Post date:** [March 6, 2019, 7:51am UTC](https://forum.glyphsapp.com/t/how-to-detect-an-outside-open-corner/4117/17 "2019-03-06T07:51:33Z")

</div>

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.
