Skip to main content
Participating Frequently
May 15, 2023
Answered

ExtendScript for Drop shadow and inner shadow with color changes

  • May 15, 2023
  • 2 replies
  • 1605 views
function DropShadow(R , G , B){

var borCol = new RGBColor();
borCol.red = R;
borCol.green = G;
borCol.blue= B;

var doc = app.activeDocument;

var style = doc.graphicStyles[2];

var rndRect = doc.selection[0]
rndRect.fillColor = borCol
 

style.applyTo(rndRect);

 
}
 
drop shadow i am getting but not reflecting exact shadow color
This topic has been closed for replies.
Correct answer m1b

Hey @m1b  Thanks for again response

Can we change the dropshadow color without filling color

Can we Only change shadow color not fillcolor

 

Do you have any idea , It would be very helpful


Yes I agree that would be helpful. Unfortunately, via scripts, we don't have access to the drop shadow information, including the shadow color. If you are applying the dropshadow the first time, it is possible to set the color, but once it is applied, we cannot change it via script. See this post for example.

- Mark

2 replies

m1b
Community Expert
Community Expert
May 20, 2023

Hi @shashank29687712glq2, this is a test I did just now:

1. set up document (see attached pdf) with "MyDropShadow" graphic style configured to be 100% opacity and 0% darkness.

2. ran this script (a slightly modified version of yours):

 

(function () {

    var doc = app.activeDocument,
        randomRGB = [
            Math.floor(Math.random() * 255),
            Math.floor(Math.random() * 255),
            Math.floor(Math.random() * 255)
        ];

    applyDropShadow(doc.selection[0], randomRGB);

    function applyDropShadow(item, rgb) {

        var c = new RGBColor();
        c.red = rgb[0];
        c.green = rgb[1];
        c.blue = rgb[2];

        var style = doc.graphicStyles.getByName('MyDropShadow');
        style.applyTo(item);
        item.fillColor = c;

    }

})();

 

 and I got pretty reasonable results:

What do you think?

- Mark

 

Edit: forgot to add demo file.

Participating Frequently
May 26, 2023

Hey @m1b Thanks for your response!

Not getting Please elaborate bit more , that would be very helpful , Thank u!

 

m1b
Community Expert
Community Expert
May 26, 2023

Hi @shashank29687712glq2, I applied a drop shadow to a square and gave it the properties that you can see in the screenshot above (multiply, opacity: 100%, darkness: 0%). Then when I changed the fillColor (can be manually or with script) the dropshadow color seems to match the square's color very well.

 

Perhaps your drop shadow settings are causing the color to not match?

Sergey Osokin
Inspiring
May 16, 2023

Have you set the shadow color in a style such as Drop Shadow > Darkness: <val>? If the exact color of the shadow is set in the effect, your function will only change the color of the object, but will certainly not change the color of the shadow in the effect settings.

Participating Frequently
May 26, 2023

Thanks @Sergey Osokin  for your answer!

But did not get Please elaborate bit more That would be helpful