Trying to create an action that will fill shape with colour automatically sampled from layer below.

Community Beginner ,
May 05, 2022 May 05, 2022

Copy link to clipboard

Copied

Hello! I have an issue I'm hoping someone can help me with. 

 

I've been using a very simple action for a few years which converts a selection into a vector shape.

 

In the screenshot you can see I have selected the bottom layer of this leaf group using the magic wand,  then the action creates a shape in a new layer above from the selection.  

 

I want to try and improve this in two ways ideally:

 

1. sample the colour of the intially selected layer (the layer I take the selection from is always a single-colour layer.) and use this as the colour of the new shape (at the moment the action is set to the orange as that what the forground colour when I first created the Action.)

 

2. Less of a proiority - have the action change the layer order when the shape has been created - so move the shape layer down so it becomes the layer that the others are clipped to. I do this manually at the moment but it would be great to know how to make an action that does this. 

 

I hope this makes sense - maybe there's a much simpler way to do this - essentially I suppose I want to convert my hand drawn layer into a vector using an action, and keep the layer placment and colour. 

 

thank you! 

TOPICS
Actions and scripting , macOS

Views

184

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
community guidelines

correct answers 1 Correct answer

Adobe Community Professional , May 05, 2022 May 05, 2022
"sample the colour of the intially selected layer (the layer I take the selection from is always a single-colour layer.) and use this as the colour of the new shape (at the moment the action is set to the orange as that what the forground colour when I first created the Action.)" Go to Actions panel menu, expand it then check Allow Tool Recording. Record step to sample color. Use Eyedropper tool. You should see step: Use eyedropper in your action.  This step will set Foreground color from spe...

Likes

Translate

Translate
Adobe Community Professional ,
May 05, 2022 May 05, 2022

Copy link to clipboard

Copied

This is really something that should be done with a script. I can be done, as I do something along those line, but I make shapes, then sample a image layer below the shape then apply the colors to a gradient to that shape. Moving layers around with scripts are easier also.

Chuck-Deco-port-004-ovals.jpg

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
community guidelines
Community Beginner ,
May 05, 2022 May 05, 2022

Copy link to clipboard

Copied

Hey Chuck,

 

thanks for the speedy response. That's good to know it's possible. Can I ask if you know of the best resources to start learning how to make these? 
cheers,

bett 

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
community guidelines
Adobe Community Professional ,
May 05, 2022 May 05, 2022

Copy link to clipboard

Copied

I would start with the free Adobe guides:

Photoshop-cc-scripting guide - it's gets your feet wet.

Photoshop-cc-scripting reference - resource for scripting, but not really up to date and a bit confusing.

Javascript-Tools-Guide - resources for javascript in mulltiple Adobe programs that use the same type of scripts: file handling, etc.

There are most likely more updated references, but that's a start.

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
community guidelines
Community Beginner ,
May 09, 2022 May 09, 2022

Copy link to clipboard

Copied

Thanks for the reccommendations - I'll take a look!

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
community guidelines
Adobe Community Professional ,
May 05, 2022 May 05, 2022

Copy link to clipboard

Copied


@Bett24334821yjkk wrote:

 

1. sample the colour of the intially selected layer (the layer I take the selection from is always a single-colour layer.) and use this as the colour of the new shape (at the moment the action is set to the orange as that what the forground colour when I first created the Action.)

 

2. Less of a proiority - have the action change the layer order when the shape has been created - so move the shape layer down so it becomes the layer that the others are clipped to. I do this manually at the moment but it would be great to know how to make an action that does this. 

 

 

#1: I'm still thinking about how this could be done with an action, this may need a script!

 

#2: Perhaps these can help (subject to layer visibility), it is good for action automation to have unique named layers to easily select them, however, if the layer is always in the same relative position in the layer stack, then use the following relative keyboard shortcuts recorded into the action to select and move layers (use Ctrl and Alt keys in Windows, ignore the + sign):

 

  • Select/target front (top) layer = Option + .
  • Select/target next layer up = Option + ]
  • Select/target next layer down = Option + [
  • Select/target back (bottom) layer = Option + ,

 

  • Move current target layer to front (top) layer = Command + Shift + ]
  • Move current target layer up = Command + ]
  • Move current target layer down = Command + [
  • Move current target layer to back (bottom) layer = Command + Shift + [

 

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
community guidelines
Adobe Community Professional ,
May 05, 2022 May 05, 2022

Copy link to clipboard

Copied

"sample the colour of the intially selected layer (the layer I take the selection from is always a single-colour layer.) and use this as the colour of the new shape (at the moment the action is set to the orange as that what the forground colour when I first created the Action.)"

 

Go to Actions panel menu, expand it then check Allow Tool Recording. Record step to sample color. Use Eyedropper tool. You should see step: Use eyedropper in your action. 

use eyedropper to select color.jpg

This step will set Foreground color from specific spot on image. Note: it will sample from image not layer if you do not set option for Eyedropper tool to sample Current Layer when playing action.

current layer eyedropper.jpg

Another note: Eyedropper tool will sample from specific, clicked point on image so you do not have great flexibility there. It seems that sample point is measured using whatever measurement unit is set for Ruler so for greater flexibility set Ruler to Percent when recording step. Action will fail in case that you do not have color at clicked point.

set ruler to percent.jpg

 

 

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
community guidelines
Adobe Community Professional ,
May 06, 2022 May 06, 2022

Copy link to clipboard

Copied

Thank you @Bojan Živković!

 

I tend to think of this option for recording brush strokes... however, it can obviously do more! I just tested and it took around 14 seconds – but at least this is possible with only an action!

 

I hacked some other script code and this takes less than 1 second... So if time is of the essence the script would be better from a speed perspective:

 

// Set the foreground colour to the centre of the document

fgColorFromDocCenterSampler();


function fgColorFromDocCenterSampler() {
    var savedRuler = app.preferences.rulerUnits;
    app.preferences.rulerUnits = Units.PIXELS;
    var docHcenter = activeDocument.width / 2;
    var docVcenter = activeDocument.height / 2;
    var colorSampler = app.activeDocument.colorSamplers.add([docHcenter, docVcenter]);
    var solidColorValue = new SolidColor();
    solidColorValue.rgb.red = Math.round(colorSampler.color.rgb.red);
    solidColorValue.rgb.green = Math.round(colorSampler.color.rgb.green);
    solidColorValue.rgb.blue = Math.round(colorSampler.color.rgb.blue);
    app.foregroundColor = solidColorValue;
    colorSampler.remove();
    app.preferences.rulerUnits = savedRuler;
}

 

This simple script samples from the middle of the document.

 

I'll post a version that samples from the middle of the active layer bounds which may be more appropriate for this use case.

 

Edit: here is a version from the layer content centre:

 

// Set the foreground colour to the centre of the active layer bounds

fgColorFromLayerBoundsCenterSampler();


function fgColorFromLayerBoundsCenterSampler() {
    var savedRuler = app.preferences.rulerUnits;
    app.preferences.rulerUnits = Units.PIXELS;
    var layerBounds = activeDocument.activeLayer.bounds;
    var layerWidth = layerBounds[2] - layerBounds[0];
    var layerHeight = layerBounds[3] - layerBounds[1];
    var layerXcenter = layerBounds[2] - layerWidth / 2;
    var layerYcenter = layerBounds[3] - layerHeight / 2;
    var colorSampler = app.activeDocument.colorSamplers.add([layerXcenter, layerYcenter]);
    var solidColorValue = new SolidColor();
    solidColorValue.rgb.red = Math.round(colorSampler.color.rgb.red);
    solidColorValue.rgb.green = Math.round(colorSampler.color.rgb.green);
    solidColorValue.rgb.blue = Math.round(colorSampler.color.rgb.blue);
    app.foregroundColor = solidColorValue;
    colorSampler.remove();
    app.preferences.rulerUnits = savedRuler;
}

 

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
community guidelines
Community Beginner ,
May 09, 2022 May 09, 2022

Copy link to clipboard

Copied

Hi Bojan, 

 

wow thanks this seems exactly what I need! so pleased it to know its achievable! Definately good to know the 'allow tool recording' is an option!

 

thanks again,

Bett

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
community guidelines
Adobe Community Professional ,
May 09, 2022 May 09, 2022

Copy link to clipboard

Copied

I hope you have better luck... When I first recorded the action, it took around 14 seconds to complete this single step. The second time it was around 20 seconds. Now after 30 seconds or so Photoshop locks up and I have to force quit.

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
community guidelines
Adobe Community Professional ,
May 10, 2022 May 10, 2022

Copy link to clipboard

Copied

At my end everything works smoothly. Which version Ps? I am using 22.5.7 I believe, previous major version.

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
community guidelines
Adobe Community Professional ,
May 10, 2022 May 10, 2022

Copy link to clipboard

Copied

Photoshop 2021 (22.5.7), Mac: 20 seconds or so in, I get the "spinning beachball of death" and Photoshop is no longer responding and requires a force quit.

 

Photoshop 2022 (23.3.1), Mac: Same as above.

 

Yes, I have reset prefs, no change.

 

The doc that the action is being played on is not the same one that recorded the action. The action is placing the 3x3 eyedropper at middle centre, 50% ruler position, so that it can work with any size doc. The test doc is 600x600px RGB 8 bpc so it shouldn't be challenging.

 

I'll try deleting and recreating the action again...

 

Edit: I have deleted and recreated the action, it now takes around a second so there must have been something funky with the original recording.

 

I have also created a version to sample from the centre of the active layer content, in addition to the first version that uses the canvas centre, all good so far.

 

eyedropper-atn.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
community guidelines
LEGEND ,
May 10, 2022 May 10, 2022

Copy link to clipboard

Copied

LATEST

It seems you found solution for your problem - please mark that as correct answer 😉

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
community guidelines