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

How to snap/round gradient rotation and stops?

Engaged ,
Sep 26, 2017 Sep 26, 2017

Copy link to clipboard

Copied

Sometiems I need to massively shake up gradient fiils — make angles rounded and position stops at multiples of, for example, five.

I'm trying to conjure up a script for this, and immidiately stopped at this part:

var NewFill = Math.round(OldFill.rotate / 5) * 5;

OldFill.rotate(NewFill, 0, 0, 1, 0);

What is wrong with it?

TOPICS
Scripting

Views

717

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

Engaged , Sep 27, 2017 Sep 27, 2017

Figured that out. RTFM.

thisDocument = app.activeDocument;

docSelection = thisDocument.selection;

selectionLen = docSelection.length;

for (i = 0; i < selectionLen; i++) {

    oldFill = docSelection;

    if (oldFill.typename == "PathItem" || oldFill.typename == "CompoundPathItem") {

        checkPath = oldFill;

        if (oldFill.typename == "CompoundPathItem") {

            checkPath = oldFill.pathItems[0];

        }

        if (checkPath.filled == true && checkPath.fillColor.typename == "GradientColor")

...

Votes

Translate

Translate
Adobe
Engaged ,
Sep 27, 2017 Sep 27, 2017

Copy link to clipboard

Copied

I'm a dumbass, I'm trying to divide a function.

Well, then, how to READ current angle of gradient fill with JS? I know well how to set it, but I need to know it first to change it.

Votes

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
Engaged ,
Sep 27, 2017 Sep 27, 2017

Copy link to clipboard

Copied

Figured that out. RTFM.

thisDocument = app.activeDocument;

docSelection = thisDocument.selection;

selectionLen = docSelection.length;

for (i = 0; i < selectionLen; i++) {

    oldFill = docSelection;

    if (oldFill.typename == "PathItem" || oldFill.typename == "CompoundPathItem") {

        checkPath = oldFill;

        if (oldFill.typename == "CompoundPathItem") {

            checkPath = oldFill.pathItems[0];

        }

        if (checkPath.filled == true && checkPath.fillColor.typename == "GradientColor") {

            if (checkPath.fillColor.gradient.type == GradientType.LINEAR) {

                //make rotation multiple of 5

                var angleVal = prompt("Make angle of gradients to be multiple of:","5","Gradient Angle")

                var oldAngle = checkPath.fillColor.angle;

                var newAngle = (Math.round(oldAngle / angleVal)) * angleVal;

                var angleDiff = newAngle - oldAngle;

                oldFill.rotate(angleDiff, 0, 0, 1, 0);

                //make stops position at multiple of 5

                var stopVal = prompt("Make gradient stops position at multiple of:","5","Gradient Stops")

                var numOfStops = checkPath.fillColor.gradient.gradientStops.length;

                for (k = 0; k < numOfStops; k++) {

                    var oldRamp = checkPath.fillColor.gradient.gradientStops.rampPoint;

                    var newRamp = (Math.round(oldRamp / stopVal)) * stopVal;

                    checkPath.fillColor.gradient.gradientStops.rampPoint = newRamp;

                }

            }

        }

    }

}

Votes

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
Community Expert ,
Sep 27, 2017 Sep 27, 2017

Copy link to clipboard

Copied

Glad we were able to help.

Votes

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
Engaged ,
Sep 27, 2017 Sep 27, 2017

Copy link to clipboard

Copied

You know how this works sometimes

Votes

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
Community Expert ,
Sep 28, 2017 Sep 28, 2017

Copy link to clipboard

Copied

LATEST

I certainly do. many times trying to explain an issue to someone who's never seen the project is enough to pull yourself out of whatever funk you're in and allow you to see a new perspective.

Votes

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