Calling for Component

Hi all,

I want to know wether there is a ‘component’ in a glyph or not.
But I cant build the right method because I dont really know whats the right ‘position’ for calling a component.

f.e.:
I got two glyphs selected. ‘A’ is ‘empty/no-nodes’ and ‘B’ is a full-component. (I want to know the difference for some branch).
Now I got this:

print Glyphs.font.selectedLayers
(
“GSLayer <0x7fcd65a98b90>: Regular (A)”,
“GSLayer <0x7fcd66e4b910>: (null) (B)”
)

But how to get the ‘null’? Or is there a better way to call?

Thx

The null is a mistake.

If you like to know if a layer has components:

for l in Glyphs.font.selectedLayers:
if len(l.componets) > 0:
print "This glyph has components"
if len(l.paths) > 0:
print “This glyph has outlines”

Hi Georg,
thank you for help, but the code doesn’t work always :frowning:
(something is wrong with the len of paths …).

I first used this:


for l in Glyphs.font.selectedLayers:

print 'paths: ',l.paths[0]
print 'comps: ',l.components[0]

if len(l.components) > 0:
print 'This glyph has components\n’
else:
print ‘glyph is empty\n’

if len(l.paths) > 0:
print ‘This glyph has outlines\n’


I got the following error-message for an ‘empty’ glyph:

Error:
Traceback (most recent call last):
File “”, line 15, in
File “/Users/Oliver/Library/Application Support/Glyphs/Scripts/GlyphsApp.py”, line 22, in len
return len(self.values())
TypeError: object of type ‘NoneType’ has no len()


I tried to fix it:

for l in Glyphs.font.selectedLayers:

print 'paths: ',l.paths[0]
print 'comps: ',l.components[0]

if len(l.components) > 0:
print ‘This glyph has components\n’

elif l.paths[0] != None:
if len(l.paths) > 0:
print ‘This glyph has outlines\n’

else:
print ‘glyph is empty\n’


Works fine.
But I cant really understand why only ‘len paths’ wont work?!
Also this dont seems to me as a ‘clean’ method

Are you running both Glyphs 1 and 2? Update them both to the latest versions, and delete these two files:

~/Library/Application Support/Glyphs/Scripts/GlyphsApp.py
~/Library/Application Support/Glyphs/Scripts/GlyphsApp.pyc

Then restart.

ok,
I have done so.

the very first script of georg seems to work fine:

empty glyph > output : n o t h i n g
outline glyph > output : … has outlines
pure component > output : … has component
outline and comp > output … has outline … hast component

so thank you again.

are there any known ‘structural-changes’ now, for ‘older’ scripts
or was this just a ‘bug’?

This was a bug.