How can I check what the type of layer.shapes?


How can I get the shape type value between GSPath and GSComponent??

layer = f.selectedLayers[0]
for item in layer.shapes:

it shows between these two types.
<objective-c class GSComponent at ~>
<objective-c class GSPath at ~>

I want to know how to get the shape type like ‘GSShapeTypeComponent’, ‘GSPath’ to check whether the shape is a path or a component.


Check the shapeType, it is either GSShapeTypePath or GSShapeTypeComponent.

How can I check it with script?
Is it possible like below code?

print(layer.shapes[0].shapeType == GSShapeTypeComponent)

You must call shapeType, like so:

Ah, the document wrote ‘shapeType’ is in ‘properties’. In your reply, it is a method(function).

Thanks a lot!

I think the Python wrapper is missing some parts here. For example, position on GSShape is wrapped for GSPath but not for GSComponent.

/cc @GeorgSeifert

That is strange. For some properties it is enough to define them on the superclass (GSShape). E.g. .locked is set for GSShape and GSComponent but works for GSPath, too. I’ll fix it.

But with position, it is the other way around. And position doesn’t make much sense for paths.

in 3.0.3(3073),
‘shapeType’ has changed to ‘bool’ type. Is it right?
Instead of ‘shapeType’, it can be checked with ‘type()’ function like below.

for shape in layer.shapes:
    print(type(shape) == GSComponent)
  	print(type(shape) == GSPath)

will it be fixed with ‘type()’ or returned to ‘shapeType’?
Or should I use layer.components and layer.paths?

Please let me know the best solution for this.
It is important for me, as I develop plugins for Hangul compositions.

Thanks in advance,

What’s the quickest way to check if a glyph contains components?

I tried something like this:

for glyph in Font.glyphs:
#	print (glyph)
	if glyph.layers[0].shapes[0].shapeType == GSShapeTypeComponent:
		print (, "contains component(s)")

It seems to work until it reaches an empty glyph such as «space»:

Traceback (most recent call last):
  File "<macro panel>", line 21
  File "GlyphsApp/GlyphsApp/", line 2844, in __getitem__
  File "GlyphsApp/GlyphsApp/", line 487, in _validate_idx
IndexError: list index 0 out of range 0
if glyph.layers[0].components:
	print("has components")
	print("has no components")
1 Like

well that is simple enough. haha
Thanks Florian!


if glyph.hasComponents():
	print("has components")
	print("has no components")

There are a bunch of methods like this that are used for the sidebar filters.

1 Like

Even simpler!

I was imagining there would be something like hasComponents() but I didn’t come across it in the forum or in the API.

In general, how can I

  1. see/lookup what methods exist and
  2. know which methods can be used with glyphs/layers/paths/etc?

Check out the mekkablue script Method Reporter :wink:


Ah yes. Keep forgetting about that.

Ok so what if instead of components I wanted to test for paths …shouldn’t there be a hasPaths()? or, for anchors hasAnchors()?

Screenshot 2022-12-08 at 14.17.41

GSLayer has hasAnchors(), hasPaths() doesn’t exist. You can always check if layer.anchors:, which essentially just returns True or False depending whether the len() of whatever you’re checking is greater than 0.

In general, you don’t need all of those functions since checking the values directly also works.

The has… functions mainly exist for features like Smart Filters which require a dedicated function to exist. When writing a Python script, this is not an issue.

All good stuff to know. Thanks.

BTW @SCarewe or @FlorianPircher if yous ever have a writing python script/building plugins workshop at a conference or otherwise, I would signup!

1 Like