Smart component's attributes via scripting


is there a way to change values of smart component’s attributes via scripting?

I have a bunch of smart components that I’d like to change an attribute.

Yes there is. I will post some sample code tomorrow (not on my Mac now).

Hey, do you remember about me? :slight_smile:

Okay, you can access a smart glyph’s settings:

smartGlyph = Glyphs.font.glyphs["_part.example"]
partsSettings = smartGlyph.partsSettings()
for j in range(len(partsSettings)):
	name = partsSettings[j].name()
	minimum = partsSettings[j].bottomValue()
	maximum = partsSettings[j].topValue()
	print "%s: from %f to %f" % ( name, minimum, maximum )

And you can access a smart component’s settings like this:


… which give s you a dictionary. The names of the properties are the keys:

properties = myComponent.pieceSettings().keys()
for thisProperty in properties:
	print "%s: %f" % ( thisProperty, myComponent.pieceSettings()[thisProperty] )

And to set a property, you simply set the key:

myComponent.pieceSettings()["depth"] = 23.5

awesome. thx!

A component gets GSNotifyingDictionary only when I change the property manually. When I add a component, pieceSettings() returns None.

How to assign this dictionary to a new component instance?

You need a smart glyph with partsSettings() in the font, and insert that smart glyph as a component. Then you should also have pieceSettings().

myGlyph.setPartsSettings_( myPartsSettings )

Look into a partsSettings() of a smart glyph (you can use the built-in function dir()) to see how it is structured.

What exactly are you trying to do?

Ok I have found it. setPieceSettings_ function sets missing property.

 for comp in selectedLayer.components:
    	properties = comp.pieceSettings()
    	if properties != None :

Could this go into the documentation please? It’s neither in Python or Core for the current (Maybe that needs rebuilding?)

We are just working on a proper wrapper and docu for it.

Hi everyone. I have a related question.
How can I set the parameters and attach the layers to the extremes via scripting?
I’ve checked the documentation but smartComponentPoleMapping and GSSmartComponentAxis are available in v2.3 and I’m on v2.2

Thanks in advance.

If you need to do it on 2.2 you can check the wrapping file and see how it works internally.

Sorry i don’t know what is a wrapping file can you tell me?

Best regards.

1 Like

Seem to be implemented, they only do work without the parenthesis now.

the parenthesis are added to properties by the pyObjC bride. We need to ‘remove’ them in with by reimplementing the them in the wrapper. Those properties you mention, are in the wrapper now.

Yes, I know :slight_smile: Just wanted to let you know, so that @mekkablue might update the snippet presented here.

Could it be changed, so that a yet untouched Smart Component (means: any component where the setting sliders are all the way down) does not return None but instead a GSNotifyingDictionary as well? Otherwise it makes programmatically access pretty tricky in certain cases.

It would be great if all possible Slider parameters would be at least there. Now you can only get the ones that have a value set. So It happens that a SC got 6 parameters, but any number between 0 and 6 is returned. You know what I mean?

I got a smart glyph/component with a parameter »Foot-length« which works inside of the Glyphs UI properly, but when reading it via code, I get this name “20803417-2298-4771-B3D3-B8194B1F4896” instead.

using pieceSettings().keys() or pieceSettings() on the component.

Is it a bug or am I not allowed to have a hyphen in the Smart Glyph parameter or so?

Can you send me the code?

Internally, it uses IDs and not names to store the slider positions. But after re-opening the file, it will use the names as ID (and not the long number/letter thing you got). So in most cases, the names are the same as the ID.