I’m trying to write a plugin to use with Glyphs3, but I’m having a problem with smartComponentValues.
for layer in Glyphs.font.selectedLayers:
for compo in layer.shapes:
if compo.name == "_part.test":
print(compo.component.smartComponentAxes)
print(compo.smartComponentValues)
print(list(compo.smartComponentValues))
When the smart component property value is set to the maximum value with the smart component setting (cmd+opt+i), the value is not output.
(
<GSSmartComponentAxis "Height">,
<GSSmartComponentAxis "Thickness">
)
<GSNotifyingDictionary 0x600013277140> {
Thickness = 5;
}
[5.0]
Meanwhile, when the smart component property value is set to the maximum value with the smart setting on the right palette, all values are output.

(
<GSSmartComponentAxis "Height">,
<GSSmartComponentAxis "Thickness">
)
<GSNotifyingDictionary 0x600013277140> {
Height = 500;
Thickness = 5;
}
[5.0, 500.0]
Currently, the value is output differently depending on how the property value of the smart component is specified. I hope all values will be printed even when it is the maximum value.
The settings omits default values. This is to save file size and avoid noice.
Here is some sample code to determine this default value:
component = Layer.selection[0]
componentGlyph = component.component
componentLayer = component.componentLayer
defaultValues = componentLayer.smartComponentPoleMapping
smartComponentAxes = componentGlyph.smartComponentAxes
for axis in smartComponentAxes:
pieceValue = component.smartComponentValues[axis.id]
if pieceValue is None:
if defaultValues[axis.id]:
if int(defaultValues[axis.id]) == 1:
pieceValue = axis.bottomValue
else:
pieceValue = axis.topValue
else:
print("nothing set for axis:", axis.name)
continue
print(axis.name, pieceValue)
Thanks. But I get a TypeError at the line.
pieceValue = component.smartComponentValues[axis.id]
File "GlyphsApp/GlyphsApp/__init__.py", line 2390, in __getitem__
TypeError: 'GSNotifyingDictionary' object is not subscriptable
Right m. I had fixed that while writing the sample. I’ll send a low level code that circumvents this until the update is out.
1 Like
When do you send out the low level code?
Sorry that I didn’t send it, yet. The issue is fixed in the latest cutting edge version.
Something like this should work.
pieceSettings = component.pieceSettings()
if pieceSettings is not None:
pieceValue = pieceSettings.objectForKey_(axis.id)
or
pieceValue = component.pieceValueForKey_(axis.id)
if pieceValue > 100000: # NSNotFound if there is no value
# get default value