Translate radial gradient center point?

Contributor ,
Jun 06, 2016 Jun 06, 2016

Copy link to clipboard

Copied

Hello,

Working from the great answer in this thread, I'm trying to move the center point of an object's gradient. Here's my test code:

var idoc = app.activeDocument;

var ipath =  idoc.selection[0];

ipath.translate(

    100, // deltaX

    100, // deltaY

    false, // transformObjects

    false, // transformFillPatterns

    true, // transformFillGradents

    false // transformStrokePattern

);

Unfortunately, nothing I try actually works.

Anyone know what the trick is to move the origin of a radial gradient?

Thanks!

TOPICS
Scripting

Views

1.3K

Likes

translate

Translate

Translate

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 guidelines

correct answers 1 Correct Answer

Adobe Community Professional , Jun 07, 2016 Jun 07, 2016
why didn't you use the code in that thread's great answer?you left out a couple of vital lines// transform gradients findings // select a path item with a gradient applied to it before running the script var idoc = app.activeDocument; var ipath =  idoc.selection[0]; var fillcolor = ipath.fillColor; ipath.filled = false; // remove previous gradient transformations, to be able to apply new ones ?? ipath.fillColor = fillcolor; // re apply the same gradient color, without transformations. ipath.fill...

Likes

translate

Translate

Translate
Adobe Community Professional ,
Jun 07, 2016 Jun 07, 2016

Copy link to clipboard

Copied

why didn't you use the code in that thread's great answer?

you left out a couple of vital lines

// transform gradients findings

// select a path item with a gradient applied to it before running the script

var idoc = app.activeDocument;

var ipath =  idoc.selection[0];

var fillcolor = ipath.fillColor;

ipath.filled = false; // remove previous gradient transformations, to be able to apply new ones ??

ipath.fillColor = fillcolor; // re apply the same gradient color, without transformations.

ipath.fillOverprint = ipath.fillOverprint; // without this, the gradient won't move or scale, but it does rotate ??

ipath.translate(

    100, // deltaX

    100, // deltaY

    false, // transformObjects

    false, // transformFillPatterns

    true, // transformFillGradents

    false // transformStrokePattern

);

Likes

translate

Translate

Translate

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 guidelines
Contributor ,
Jun 07, 2016 Jun 07, 2016

Copy link to clipboard

Copied

Hi Carlos!

CarlosCanto wrote:

why didn't you use the code in that thread's great answer?

you left out a couple of vital lines

Good question.

I actually did use your code, which ended up working (the gradient I tested on was moved/skewed).

When I tried just moving (not skewing/scaling) nothing seemed to change (I tried both .translate and .transform). Sorry that I did not specify this in my original question.

Anyway, thanks so much for your reply and help! I will try your example code when I get home later today and let you know how it goes.

I really appreciate your help!

Cheers,

Micky

Likes

translate

Translate

Translate

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 guidelines
Contributor ,
Jun 07, 2016 Jun 07, 2016

Copy link to clipboard

Copied

Hi Carlos!

Not sure if I am doing something wrong, but I can't seem to get this code to work:

#target illustrator

#targetengine main

var idoc = app.activeDocument;

var ipath =  idoc.selection[0];

var fillcolor = ipath.fillColor;

ipath.filled = false; // remove previous gradient transformations, to be able to apply new ones ??

ipath.fillColor = fillcolor; // re apply the same gradient color, without transformations.

ipath.fillOverprint = ipath.fillOverprint; // without this, the gradient won't move or scale, but it does rotate ??

ipath.translate(

    100, // deltaX

    100, // deltaY

    false, // transformObjects

    false, // transformFillPatterns

    true, // transformFillGradents

    false // transformStrokePattern

);

Here's the file I am working on:

https://dl.dropboxusercontent.com/u/1277106/illy-gradient-offset.ai

Can you tell if I am overlooking something?

The original script you posted does work (transform/skew), but it seems like translate doesn't work by itself. What do you think?

Thanks so much for your help, I greatly appreciate it.

Micky

Likes

translate

Translate

Translate

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 guidelines
Adobe Community Professional ,
Jun 07, 2016 Jun 07, 2016

Copy link to clipboard

Copied

are you bringing this shape from another application? it has some sort of appearance that is preventing the script from working. Use "Reduce to basic appearance" to clear it out, that will make the script work on your shape.

Likes

translate

Translate

Translate

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 guidelines
Contributor ,
Jun 08, 2016 Jun 08, 2016

Copy link to clipboard

Copied

CarlosCanto wrote:

are you bringing this shape from another application? it has some sort of appearance that is preventing the script from working. Use "Reduce to basic appearance" to clear it out, that will make the script work on your shape.

Ahhh, great catch! Thank you so much for catching that.

I will try that tonight. Looks like copying all of the objects attributes, reducing appearance, re-applying gradient (like your script does) and then re-applying previous appearance is the direction I'll head.

I'll post back my findings soon!

Thanks so much Carlos! I really appreciate your help!

Likes

translate

Translate

Translate

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 guidelines
Contributor ,
Jun 08, 2016 Jun 08, 2016

Copy link to clipboard

Copied

CarlosCanto wrote:

are you bringing this shape from another application? it has some sort of appearance that is preventing the script from working. Use "Reduce to basic appearance" to clear it out, that will make the script work on your shape.

That did the trick! I'm not sure what the appearance thing was. At one point I had rasterize applied to the top layer ... Anyway, reducing appearance did the trick.

Thanks a bunch for your help!!!!

Likes

translate

Translate

Translate

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 guidelines
Adobe Community Professional ,
Jun 09, 2016 Jun 09, 2016

Copy link to clipboard

Copied

you're welcome, glad to hear it worked

Likes

translate

Translate

Translate

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 guidelines
Contributor ,
Jun 11, 2016 Jun 11, 2016

Copy link to clipboard

Copied

CarlosCanto wrote:

you're welcome, glad to hear it worked

Definitely!

In fact, here's the script that I created based on your original code:

GitHub - mhulse/illy-nudge: Nudge gradient centerpoint.

(Note: Only tested on my Mac)

Thanks again for all of your help!!!!! I really appreciate it.

Likes

translate

Translate

Translate

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 guidelines
Adobe Community Professional ,
Jun 12, 2016 Jun 12, 2016

Copy link to clipboard

Copied

it works great on Win10, CC2015, thanks for sharing!!

Likes

translate

Translate

Translate

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 guidelines
Contributor ,
Jun 12, 2016 Jun 12, 2016

Copy link to clipboard

Copied

CarlosCanto wrote:

it works great on Win10, CC2015, thanks for sharing!!

Oh, cool!! That's good news. I wasn't sure if there would be any OS-specific things to consider.

Thanks for testing (and for all of your help too)!

Likes

translate

Translate

Translate

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 guidelines