Change gradient in native Color Layer via Scripting

Hey everyone,
I have some trouble navigating how to change/apply gradient fills to shapes via the Macro Console. Does anybody have some experience with this?
My goal is to apply the same gradient to all closed paths (shapes that are in a native Color Layer).
I have been inspecting manually predefined gradients with print(thisPath.attributes['gradient']) → for example <GSGradient 0x60000032e500> 2 colors
I found (GSGradient Class Reference) as a reference, but couldn’t really understand how exactly the syntax works and how to apply it to my goal.
Greetings & Thanks!

The gradient is not covered by the python wrapper and docu. I’ll see that I can add it. Until then you can use the native API that is provided by pyobjc. How to translate the ObjectiveC syntax to python is explained here: An introduction to PyObjC — PyObjC - the Python to Objective-C bridge

1 Like

If you just need to propagate the same gradient from one path to the other, you can just copy it and add it

gradient = path.attributes['gradient']
for path in paths:
    path.attributes["gradient"] = gradient.copy()
1 Like

Thank you so much! With these hints I was able to solve my issue!