Add component and set width

i try to generate a script to auto add comonent and set width of the component

for component in layer.components:
	print(component.smartComponentValues["Width"])

seem nothing there in the documention

thank you

If you want to change the value, you would assign a new value like so:

for component in layer.components:
	component.smartComponentValues["Width"] = 50

i’ve tried this before but it’s not working component width is not changing

It works for me. Can you send me the file?

And there is some documentation: Glyphs.app Python Scripting API Documentation — Glyphs.app Python Scripting API 3.2 documentation

The smartComponentValues use an axis key to axes the values. For newly added smart components, that is a random string, when you save and re-open the file, that ID will be equal to the axis name.
The docu tries to explains. But here is a better example (I updated the docu, will be online soonish)

component = Layer.shapes[0]
widthAxis = component.component.smartComponentAxes['Width']
component.smartComponentValues[widthAxis.id] = 50

widthAxis = component.component

Component dot component?

Is that really how it should be? That reads a little hiccupy to me, python-object-wise.

That depends on your variable naming. The component property on a GSComponent points to the referenced glyph.

Speaking of that, I always found that awkward in the api. For my understanding the GSComponent is the component and the referenced glyph should be something like glyph or source as property name IMO.

Maybe that could be changed and you leave the component as an alias for backwards compatibility?

1 Like