When a smart component’s custom property has its top value, Glyphs doesn’t recognize the component.
For example, I added a property named ‘StemWidth’ in a smart component with a bottom value of ‘0’ and a top value of ‘240’. When the value was set at 220, I could access and print the value with component.smartComponentValues[‘StemWidth’]. However, when the value was set at 240, the KeyError Exception happened. Also, when I printed the dictionary, I couldn’t find the ‘StemWidth’ property. But it was still in the smartComponentAxes.name, though.
Plus, this error didn’t occur when the property was Height or Width.
#MenuTitle: Show Component Property Value
# -*- coding: utf-8 -*-
Glyphs script for showing the value of the requested smart component property
# Author : todoi
# Date : 2019/02/01
from GlyphsApp import *
componentSearch ='_partT1.V-ddigeut-2a' # change here!
propertyToLookFor='Width' # change here!
# glyph selection is needed
print('Select some glyphs first')
#for glyphs e.g.) 'Ddag-ko','Ddarh-ko',...
for layer in Glyphs.font.selectedLayers:
#for components e.g.) dot, stem, ttigeut, ...
for component in layer.components:
#try to return the value of seeked property
# first %s: glyph name
# second %s: property that you required
# final %d: value of that property
print('Glyph:%s, %s Value: %d' %(unichr(int(layer.parent.unicode,16)),propertyToLookFor,component.smartComponentValues[propertyToLookFor]))
#KeyError occurs in 2 circumstances
#1st: the value of the property is at the maximum: BUG
#2nd: there's no such property
#if there was actually a propery that you required
#look up all smartComponets one more time
for axis in component.component.smartComponentAxes:
#if there was one, then, it might had a maximum value
print('Glyph:%s, %s Value: %d' %(unichr(int(layer.parent.unicode,16)),propertyToLookFor,axis.topValue))
#if there is not, then you probably entered a wrong property name
print('Glyph:%s, the glyph has no such property: %s'%(unichr(int(layer.parent.unicode,16)),propertyToLookFor))
The script itself works fine, but I think the value that is equal to the default should be visible, too.
When the value is equal to the default, it is not stored in the smartComponentValues but the component axis name is still stored in the smartComponentAxes.names. Using that, I handled the KeyError making the script work fine. Still, I think the value should be stored in the smartComponentValues even if it has the default value, and thought it was kind of a bug.