Highlighted

Is it possible to pick color from to another layer using scripting?

Participant ,
May 25, 2020

Copy link to clipboard

Copied

Here's what I want to achieve.

Let's say I've two rectangles filling an artboard in two half. one of the rectangle have fill color.

and I want a script that actually picks up the fill color from that rectangle's center position and fill that color on other rectangle. Here I don't want to use fill color property of the layer, I want to use position property of layer to pick the color. How can I do that?

 

Thanks in advance.

TOPICS
How to, Scripting

Views

1.2K

Likes

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

Is it possible to pick color from to another layer using scripting?

Participant ,
May 25, 2020

Copy link to clipboard

Copied

Here's what I want to achieve.

Let's say I've two rectangles filling an artboard in two half. one of the rectangle have fill color.

and I want a script that actually picks up the fill color from that rectangle's center position and fill that color on other rectangle. Here I don't want to use fill color property of the layer, I want to use position property of layer to pick the color. How can I do that?

 

Thanks in advance.

TOPICS
How to, Scripting

Views

1.2K

Likes

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
May 25, 2020 0
Most Valuable Participant ,
May 25, 2020

Copy link to clipboard

Copied

Hi @AdiraiMaji,

I think I didn't understand.

 

Can you show something? Before and after? With opened Layers Panel?

Likes

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
Reply
Loading...
May 25, 2020 1
Participant ,
May 25, 2020

Copy link to clipboard

Copied

20200525_214949.gif

 

(Sorry for the glitch in screen recording) I've two layers. Layer 1 is fully red. Layer 2 is gray most part and in the center it's green.

 

I want to change the red layer to green (which is center of layer2) via scripting. I want to use layer 2's center point color to apply on layer 1. Hope you got my question now. I want to use the  layer's center point as color picking area.... Is it possible?

Likes

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
Reply
Loading...
May 25, 2020 0
Most Valuable Participant ,
May 25, 2020

Copy link to clipboard

Copied

No apology is required.

I see what you want - but I don't think that is possible in a way like this.

 

The only two variants (except in actions) for calling a ColorPicker (that I know) in Javascript are:

 

var col1 = app.showColorPicker(new RGBColor());
alert (col1.red+" "+col1.green+" "+col1.blue);
var col2 = $.colorPicker();
alert (col2);

 

 

-----------------------

Unfortunately your screen recording is very very small, more like a stamp. There is not so much to see.

 

But it seems:

  • you have two layers
  •  not layer#1 is red --> in layer#1 is a red rectangle over the whole artboard
  • in layer#2 there are two rectangles - a big grey one and a small green one

 

Why not looking for the smaller rectangle in layer#2, gets it's fill color and set this color as fill color for the rectangle in layer#1 ? For my part this could be a good and possible solution.

 

Maybe you could show one screenshot (again) but bigger and with (really) opened Layers Panel (to see all existing paths) or upload a sample file (with no private informations) to a hoster of your choice and link to here?

 

Likes

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
Reply
Loading...
May 25, 2020 2
Participant ,
May 25, 2020

Copy link to clipboard

Copied

Thank you for response..

Why not looking for the smaller rectangle in layer#2, Because I just shown what I needed in easy example. Instead of rectangle in layer#2 I've bunch of images here.I just want to eyedrop the center of that image to layer#1.

 

In this time I'll show you the example with image in layer#2

 

I just want to know how to use eyedropper tool automatic way using script. and detect the center of a layer and it's position on artboard. This would help to accomplish the need.

 

Delete.gif

 

Likes

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
Reply
Loading...
May 25, 2020 0
Enthusiast ,
May 26, 2020

Copy link to clipboard

Copied

Salut!

var docRef = app.activeDocument;
docRef.layers[1].pathItems[0].fillColor = docRef.layers[0].pathItems[0].fillColor;

Bon courage...

 

Likes

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
Reply
Loading...
May 26, 2020 0
Participant ,
May 26, 2020

Copy link to clipboard

Copied

Thank you so much... One of my doubt has bee cleared. I've some direction now.
By the way your code is applying first layer's fillColor to second layer's fillColor. Any how I got that point.

I just need to switch layers[0] and layers[1]

 

But I've got a problem now. The second layer item isn't a pathItem it has image instead. If I go for flatten Transparency. It would make layer structure with multiple pathItems depends on the colors in the image. So I just want to read the color of image in center point How can I do that?? I mean as you can see in above screen record the gray and green layer is an image file (RasterItem) so if I use your code it will throw error. I just need to read the color of image file's center position using script and apply that color (green in this case) to layer 1 fill color. How can I do that?

Likes

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
Reply
Loading...
May 26, 2020 0
Enthusiast ,
May 26, 2020

Copy link to clipboard

Copied

Erreur pour moi, je n'avais pas remarqué que c'était une image.

Dans ce cas, je n'ai pas de réponse, désolé...

 

 

Likes

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
Reply
Loading...
May 26, 2020 1
Participant ,
May 26, 2020

Copy link to clipboard

Copied

It's okay. You've given me a direction to think.. Thank you for the code....

Likes

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
Reply
Loading...
May 26, 2020 0
Enthusiast ,
May 26, 2020

Copy link to clipboard

Copied

Rebonjour,

Après réflexion, j'ai trouvé une piste.

le script doit:

1 dupliquer l'image,

2 vectorisez l'image dupliquée (paramètres à voir 2 couleurs)

3 capturer la couleur de la partie centrale

4 supprimer les éléments créés

4 attribuer cette couleur à l'objet rouge pour qu'il devienne vert

Je peux faire cela, de ton coté, tu dois créer un paramètre prédéfini à utilisez dans le script.

René

renél80416020_0-1590497637796.png

 

 

Likes

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
Reply
Loading...
May 26, 2020 0