• Global community
• Language:
• Deutsch
• English
• Español
• Français
• Português
• 日本語コミュニティ
Dedicated community for Japanese speakers
• 한국 커뮤니티
Dedicated community for Korean speakers
Exit

Participant ,
Jan 08, 2023 Jan 08, 2023

Copied

is there a way to select a bunch of gradients filled shapes and say :
switch from linear to radial ?

Instead of Having to click on each individual shape and go to the gradient panel and change from linear to radial

See attachment for example

thxxxx

-
www.instagram.com/mugen_labz/
TOPICS
Scripting

Views

327

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Guide , Jan 08, 2023 Jan 08, 2023
``````/*
* Changes gradient type, from linear to radial, of selected path items
* Femke Blanco 08/01/2023
*/
var doc = app.activeDocument;
for (var i = 0; i < doc.selection.length; i++) {
}
for (var j = 0; j < l; j++) {
if (j == 0) {
...

Community Expert , Jan 08, 2023 Jan 08, 2023

Hi @Max Mugen, I had already written this when I saw you already had a virtually equivalent answer. I will post it anyway, because a small difference is I gave it a UI, so you can choose which conversion to make. - Mark

``````/**
*/
(function () {

var doc = app.activeDocument,
items = doc.selection;

``````
...

13 Replies 13
Guide ,
Jan 08, 2023 Jan 08, 2023

Copied

``````/*
* Changes gradient type, from linear to radial, of selected path items
* Femke Blanco 08/01/2023
*/
var doc = app.activeDocument;
for (var i = 0; i < doc.selection.length; i++) {
}
for (var j = 0; j < l; j++) {
if (j == 0) {
initialise(stop, 0);
} else if (j == l - 1) {
var stop = g2.gradientStops[l - 1];
initialise(stop, l - 1);
} else {
initialise(stop, j);
}
}
function initialise(stop, index) {
}
}``````

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Expert ,
Jan 08, 2023 Jan 08, 2023

Copied

Hi @femkeblanco, I wrote a script like this too (I will post it, too, only because it has a UI), and both our scripts create a swatch item for every gradient we make. Any idea how to avoid that? I fiddled for quite a while but couldn't solve it. I feel like I'm missing something obvious.

- Mark

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Guide ,
Jan 08, 2023 Jan 08, 2023

Copied

Hi @m1b.  I didn't notice the added swatches.  I presume it's because the scripts create new gradient colors, in which case I don't think there's a way around it.

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Engaged ,
Jan 09, 2023 Jan 09, 2023

Copied

Also a big problem with the fact that gradients on objects are stored in the document structure as invisible to the user global swatches. Changing the gradient of one object changes all the copies in the document. We discussed this scripting problem with the Adobe Illustrator team, but as we can see in the CC 2023 script API it hasn't been solved.

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Expert ,
Jan 09, 2023 Jan 09, 2023

Copied

Thanks Sergey. Yes it's a bit of a mess.

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Participant ,
Jan 08, 2023 Jan 08, 2023

Copied

Thank youuuuu 😄

-
www.instagram.com/mugen_labz/

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Expert ,
Jan 08, 2023 Jan 08, 2023

Copied

Hi @Max Mugen, I had already written this when I saw you already had a virtually equivalent answer. I will post it anyway, because a small difference is I gave it a UI, so you can choose which conversion to make. - Mark

``````/**
*/
(function () {

var doc = app.activeDocument,
items = doc.selection;

for (var i = 0; i < items.length; i++) {

var item = items[i];

if (
)

}

}

};

function ui() {

var w = new Window("dialog { text:'', properties:{ resizeable:true } }");
var buttons = w.add("group {orientation:'row', alignment:['right','center'], alignChildren:'right', margins:[0,23,0,0] }");
var cancelButton = buttons.add("Button { text:'Cancel', properties:{name:'cancel'} }");
var okButton = buttons.add("Button { text:'Convert' }");
okButton.onClick = function () { w.close(1) };

w.center();
var result = w.show();

if (result == 1)

}

})();``````

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Participant ,
Jan 08, 2023 Jan 08, 2023

Copied

Thank you for posting your solution ! it is very nice also to be able to choose (just because ^^ )
Elegant solution too

Fun fact, I was editing the file from femkeblanco to transform to radial or linear, annnd it worked ! haha
Besides that, I have no clue about the code, too many var in there !

-
www.instagram.com/mugen_labz/

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Expert ,
Jan 08, 2023 Jan 08, 2023

Copied

It's amazing what we can achieve sometimes! Keep it up. It takes a lot of playing around for the concepts to become clear.

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Expert ,
Jan 08, 2023 Jan 08, 2023

Copied

Also, because neither @femkeblanco or I explicitly stated the fact I will say it here: this task would be trivial if you could just set the gradient's type directly. That would have been a nice one-line of script. Oh well.

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Participant ,
Jan 08, 2023 Jan 08, 2023

Copied

well, i'm not sure of what you are referring to here ^^' am I missing something ?
If I draw, I'll know beforehand what kind of gradient I want to use. Some minors change in the artwork would not justify using a script here.

But this time around, I'm finally going down the rabbit hole of making my own libraries of assets. Swatches here but it is a long road to go.
In my libs  I find it nice to have both versions of the gradient at hand because I'll probably go over an existing artwork and try to polish it and make it pop enough for publishing.
At this stage, re edit a lot of stuff can be tedious and every click can be a time saver. Plus the fact of happy creative accidents ? so yea I'll take both and mess around 😄 File cleaning would be next day then haha

-
www.instagram.com/mugen_labz/

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Expert ,
Jan 09, 2023 Jan 09, 2023

Copied

Sorry I wasn't clear and it seems I was giving you unnecessary info anyway. 🙂 I was trying to explain why femkeBlanco's and my code was so long-winded just to change the type of a gradient. The reason is that gradients aren't completely implemented in the scripting API, and perhaps poorly designed in so far as they have been. We *should* be able to script this one line to do what you ask:

``item.fillColor.gradient.type == GradientType.RADIAL;``

But alas that doesn't do anything.

- Mark

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Participant ,
Jan 09, 2023 Jan 09, 2023

Copied

LATEST

ooh ok you were referring to the API !
thx for explaining
Well this was the line of code I was adventurous enough to change and try anyway haha
gland it worked because of all the rest of the code

cheers !

-
www.instagram.com/mugen_labz/