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:

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: Python Scripting API Documentation — 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[] = 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