Set Smart Component Value via Script (not working)

I am trying to set a smart component value according to the Documentation

Here’s my attempt with the attached file:

glyph = Font.glyphs['A']
propertyName = 'H longer'
component = glyph.layers[0].components[0]
component.smartComponentValues[propertyName] = 50
print(component.smartComponentValues[propertyName])

This ^ does not do anything visible to the component, but it prints the updated value.

The part in the Docu that I refer to is this one where it shows an example like so:

# Narrow shoulders of m
glyph = font.glyphs['m']
glyph.layers[0].components[1].smartComponentValues['shoulderWidth'] = 30 # First shoulder. Index is 1, given that the stem is also a component with index 0
glyph.layers[0].components[2].smartComponentValues['shoulderWidth'] = 30 # Second shoulder. Index is 2, given that the stem is also a component with index 0

I am always a bit confused with the SC API, there was also something with pieceSettings and partSettings … anyway

  1. How can I set the value?
  2. And if it’s different from the documentation, the documentation might need an update
  3. The docu could also need an update where the examples use font or layer instead of Font or Layer, so that novices can use them quicker.

SC Test.glyphs.zip (2.9 KB)

This should work. At least it works in my testing. Are you sure the property name is correct (use an uppercase L in 'H Longer')?

partSettings is the low-level Objective-C API.

Ah thanks, sorry, there was indeed a lowercase mistake on my side.

But I managed to update the file where It still does not work. We tested now on different macs in 3151 and 3180.

This file now has 2 Smart Glyphs (marked red) with slightly different settings)
_smart.test.FAULTY is used in “D”, _smart.test.FAULTY.TEST is used in “E”
(Sorry for the names, we tried a lot of things to reproduce it and once we had the thing that fails, we did not want to change a thing, in order the keep the file “faulty”)

run this script with either D or E for the glyph to affect, and it does not work (here)

glyph = Font.glyphs['E']
propertyName = 'Adjusted'
component = glyph.layers[0].components[0]
component.smartComponentValues[propertyName] = 50
print(component.smartComponentValues[propertyName])

I assume the cause might be in the smart settings?
Thanks so much!

SC Test.glyphs.zip (3.4 KB)

The script seems to work in the D and E for me.

Weird, it does not work here. Also today not. But thanks for checking!

Edit:
For the record, after some debugging with Georg, we found that you need to save, close and re-open the file after adding a new Smart Component property. So it all works, generally :+1:

This seems to be fixed in version 3.2.