• 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 update Solid Color adjustment layer color using Photoshop scripting?

Explorer ,
Apr 04, 2023 Apr 04, 2023

Copy link to clipboard

Copied

Hi everyone, 

 

Mission: 

Fix a script where the solid color adjustment layer is selected (or created) and allows the user to pick a color from either a color picker functionality or the adjustment layer settings per se.

 

Is it possible to prompt the user to select a new color using the color picker or any other way?

 

In my script i managed to make something similar where the script will edit a normal layer and ask the user to:

- color pick a color

- then click ok = Layer fills with this color

- If user wants to change color, a new prompt comes up and allows user to edit color

- If user clicks ok again = Layer fills with new color

 

This works fine, but with a normal layer.

 

I ahvent been able to make this work but using a Solid Color adjustment layer instead, is it possible?

Reason: Currently, with the normal layer fill with new color functionality, photoshop needs to refresh the document for a second in order for the user to see the new color selected from the color picker before it asks the user if color is ok to continue the process.

 

I would like this to be a solid color layer instead, so that we can see how the color looks while choosing different colors directly in the color picker. Functionality i see only happens when editing a Solid Color adjustment layer. 

 

I hope this does make sense! 

Here are 2 functions i had but do not work.

 

 

I believe its not editing the soldid color layer properly?

 

function updateColorFillLayer(doc, colorFillLayer, fillColor) {
    if (colorFillLayer.kind === LayerKind.SOLIDFILL) {
        var desc = new ActionDescriptor();
        var ref = new ActionReference();
        
        ref.putIdentifier(charIDToTypeID('AdjL'), colorFillLayer.id);
        desc.putReference(charIDToTypeID('null'), ref);

        var colorDesc = new ActionDescriptor();
        colorDesc.putDouble(charIDToTypeID('Rd  '), fillColor.rgb.red);
        colorDesc.putDouble(charIDToTypeID('Grn '), fillColor.rgb.green);
        colorDesc.putDouble(charIDToTypeID('Bl  '), fillColor.rgb.blue);
        desc.putObject(charIDToTypeID('T   '), charIDToTypeID('SoCo'), colorDesc);

        try {
            executeAction(charIDToTypeID('setd'), desc, DialogModes.NO);
        } catch (e) {
            alert("Error: " + e.message);
        }
    } else {
        alert("The specified layer is not a Solid Color adjustment layer.");
    }
}

 

 

 

 

function updateColorFillLayer(doc, colorFillLayer) {
    if (colorFillLayer.kind === LayerKind.SOLIDFILL) {
        doc.activeLayer = colorFillLayer;
        var idAdjs = charIDToTypeID("Adjs");
        executeAction(idAdjs, undefined, DialogModes.ALL);
    } else {
        alert("The specified layer is not a Solid Color adjustment layer.");
    }
}

 

 

 

 

TOPICS
Actions and scripting , Windows

Views

1.4K

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

Community Expert , Apr 04, 2023 Apr 04, 2023

@Sergio Luis28770527a94r – Try this, I'm pretty happy with it, much better than my previous code offerings!

 

#target photoshop

/*
Interactive Color Fill.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/how-to-update-solid-color-adjustment-layer-color-using-photoshop-scripting/td-p/13702428
v1.0 - 4th April 2023, Stephen Marsh
*/

if (app.documents.length > 0) {

    if (activeDocument.activeLayer.kind == LayerKind.SOLIDFILL) {

        interactiveSetColorFill();

    } else {
...

Votes

Translate

Translate
Adobe
Community Expert ,
Apr 04, 2023 Apr 04, 2023

Copy link to clipboard

Copied

@Sergio Luis28770527a94r – The following script will create a new solid fill layer via a colour picker:

 

https://community.adobe.com/t5/photoshop-ecosystem-discussions/no-solid-color/m-p/11568895#U11568895

 

/* https://community.adobe.com/t5/photoshop/no-solid-color/m-p/11568895 */
/* https://feedback.photoshop.com/conversations/photoshop/photoshop-2021-windows-cant-make-fill-layer-windows/5f9a513249d3ca3d56ba9d11 */

// Add Solid Fill Layer via Color Picker GUI.jsx

#target photoshop

if (app.documents.length > 0) {

    getColorpickerColor();

    /* https://community.adobe.com/t5/photoshop/get-photoshop-foreground-color-as-rgb-value/td-p/9402156 */
    var fColor = app.foregroundColor;
    var R = fColor.rgb.red.toFixed(2);
    var G = fColor.rgb.green.toFixed(2);
    var B = fColor.rgb.blue.toFixed(2);

    /* Clean SL Code for SOLIDFILL layer */
    makeFill(R, G, B);
    function makeFill(red, Grn, blue) {
        var c2t = function (s) {
            return app.charIDToTypeID(s);
        };

        var s2t = function (s) {
            return app.stringIDToTypeID(s);
        };

        var descriptor = new ActionDescriptor();
        var descriptor2 = new ActionDescriptor();
        var descriptor3 = new ActionDescriptor();
        var descriptor4 = new ActionDescriptor();
        var reference = new ActionReference();

        reference.putClass(s2t("contentLayer"));
        descriptor.putReference(c2t("null"), reference);
        descriptor4.putDouble(s2t("red"), red);
        descriptor4.putDouble(c2t("Grn "), Grn);
        descriptor4.putDouble(s2t("blue"), blue);
        descriptor3.putObject(s2t("color"), s2t("RGBColor"), descriptor4);
        descriptor2.putObject(s2t("type"), s2t("solidColorLayer"), descriptor3);
        descriptor.putObject(s2t("using"), s2t("contentLayer"), descriptor2);
        executeAction(s2t("make"), descriptor, DialogModes.NO);
    }

    /* https://graphicdesign.stackexchange.com/questions/125917/how-can-i-get-an-rgb-color-using-photoshops-color-picker-instead-of-systemss */
    function getColorpickerColor() {
        if (app.showColorPicker()) {
            return app.foregroundColor;
        }
        else {
            return false;
        }
    }

} else {
    alert('You must have a document open!');
}

 

The following function will edit an existing solid colour fill layer:

 

setColorFill(0, 0, 255);

function setColorFill(red, grain, blue) {
	function s2t(s) {
        return app.stringIDToTypeID(s);
    }
	var descriptor = new ActionDescriptor();
	var descriptor2 = new ActionDescriptor();
	var descriptor3 = new ActionDescriptor();
	var reference = new ActionReference();
	reference.putEnumerated( s2t( "contentLayer" ), s2t( "ordinal" ), s2t( "targetEnum" ));
	descriptor.putReference( s2t( "null" ), reference );
	descriptor3.putDouble( s2t( "red" ), red );
	descriptor3.putDouble( s2t( "grain" ), grain );
	descriptor3.putDouble( s2t( "blue" ), blue );
	descriptor2.putObject( s2t( "color" ), s2t( "RGBColor" ), descriptor3 );
	descriptor.putObject( s2t( "to" ), s2t( "solidColorLayer" ), descriptor2 );
	executeAction( s2t( "set" ), descriptor, DialogModes.NO );
}

 

You could transplant the code to create a solid fill via the picker from the first script, into the second script to update an existing solid fill colour layer.

 

Hope this helps!

 

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 ,
Apr 04, 2023 Apr 04, 2023

Copy link to clipboard

Copied

@Sergio Luis28770527a94r – Here is a sample with both scripts combined:

 

/*
Change Solid Fill Layer via Color Picker.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/how-to-update-solid-color-adjustment-layer-color-using-photoshop-scripting/m-p/13702428
v1.0 - 4th April 2023, Stephen Marsh
*/

#target photoshop

if (app.documents.length > 0) {

    if (activeDocument.activeLayer.kind == LayerKind.SOLIDFILL) {

        var savedForegroundColor = app.foregroundColor;
        getColorpickerColor();
        var fColor = app.foregroundColor;
        var rValue = fColor.rgb.red.toFixed(2);
        var gValue = fColor.rgb.green.toFixed(2);
        var bValue = fColor.rgb.blue.toFixed(2);
        setColorFill(rValue, gValue, bValue);
        app.foregroundColor = savedForegroundColor;


        ///// FUNCTIONS /////

        function getColorpickerColor() {
            if (app.showColorPicker()) {
                return app.foregroundColor;
            } else {
                return false;
            }
        }

        function setColorFill(red, grain, blue) {
            function s2t(s) {
                return app.stringIDToTypeID(s);
            }
            var descriptor = new ActionDescriptor();
            var descriptor2 = new ActionDescriptor();
            var descriptor3 = new ActionDescriptor();
            var reference = new ActionReference();
            reference.putEnumerated(s2t("contentLayer"), s2t("ordinal"), s2t("targetEnum"));
            descriptor.putReference(s2t("null"), reference);
            descriptor3.putDouble(s2t("red"), red);
            descriptor3.putDouble(s2t("grain"), grain);
            descriptor3.putDouble(s2t("blue"), blue);
            descriptor2.putObject(s2t("color"), s2t("RGBColor"), descriptor3);
            descriptor.putObject(s2t("to"), s2t("solidColorLayer"), descriptor2);
            executeAction(s2t("set"), descriptor, DialogModes.NO);
        }

    } else {
        alert("The active layer isn't a Color Fill layer!");
    }

} else {
    alert('You must have a document open!');
}

 

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
Explorer ,
Apr 04, 2023 Apr 04, 2023

Copy link to clipboard

Copied

Hi Stephhen,

 

Appreciate you helping me out and combining both scripts to complete it.

I tried it and works great, i will now try implementing it into my current longer script.

One question though, ideally, i would like the solid color adjustment layer to reflect the chosen color from the color picker window,  Live, in as its default functionality when you double click on the solid color layer thumbnail.

right now, the script prompts me to pick a new color, but only is reflected after one click OK.

 

Is this possible to achieve? thanks!

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 ,
Apr 04, 2023 Apr 04, 2023

Copy link to clipboard

Copied

@Sergio Luis28770527a94r – Yes it's possible, but ideally you would first get the values of the current fill layer, then set them into the setColorFill function and change DialogModes.NO to DialogModes.ALL

 

Getting the values of the current fill layer may be easier said than done, I'm guessing it would take some advanced Action Manager code...

 

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 ,
Apr 04, 2023 Apr 04, 2023

Copy link to clipboard

Copied

@Sergio Luis28770527a94r – Try this, I'm pretty happy with it, much better than my previous code offerings!

 

#target photoshop

/*
Interactive Color Fill.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/how-to-update-solid-color-adjustment-layer-color-using-photoshop-scripting/td-p/13702428
v1.0 - 4th April 2023, Stephen Marsh
*/

if (app.documents.length > 0) {

    if (activeDocument.activeLayer.kind == LayerKind.SOLIDFILL) {

        interactiveSetColorFill();

    } else {
        alert("The active layer isn't a Color Fill layer!");
    }

} else {
    alert('You must have a document open!');
}


function interactiveSetColorFill() {
    /*
    Get the colour fill RGB values
    https://community.adobe.com/t5/photoshop-ecosystem-discussions/get-current-solid-layer-color-hex-code-in-alert/td-p/10830649
    */
    var r = new ActionReference();
    r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("adjustment"));
    r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
    var objAdjustment = executeActionGet(r).getList(stringIDToTypeID("adjustment"));
    var objsolidColorLayer = objAdjustment.getObjectValue(0);
    var objRGBColor = objsolidColorLayer.getObjectValue(stringIDToTypeID("color"));
    var rValue = Math.round(objRGBColor.getDouble(stringIDToTypeID("red")));
    var gValue = Math.round(objRGBColor.getDouble(stringIDToTypeID("grain")));
    var bValue = Math.round(objRGBColor.getDouble(stringIDToTypeID("blue")));
    /*
    Set the colour fill RGB values
    */
    function s2t(s) {
        return app.stringIDToTypeID(s);
    }
    var descriptor = new ActionDescriptor();
    var descriptor2 = new ActionDescriptor();
    var descriptor3 = new ActionDescriptor();
    var reference = new ActionReference();
    reference.putEnumerated(s2t("contentLayer"), s2t("ordinal"), s2t("targetEnum"));
    descriptor.putReference(s2t("null"), reference);
    descriptor3.putDouble(s2t("red"), rValue);
    descriptor3.putDouble(s2t("grain"), gValue);
    descriptor3.putDouble(s2t("blue"), bValue);
    descriptor2.putObject(s2t("color"), s2t("RGBColor"), descriptor3);
    descriptor.putObject(s2t("to"), s2t("solidColorLayer"), descriptor2);
    executeAction(s2t("set"), descriptor, DialogModes.ALL);
}

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
Explorer ,
Apr 04, 2023 Apr 04, 2023

Copy link to clipboard

Copied

GG My friend.

It does exactly that. I've been trying to figure this out myself haha.

 

Im going to try implementing this in my code.

If i encounter any other thing, ill hop back in, but for now ill mark your answer as the GOAT.

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
Explorer ,
Apr 04, 2023 Apr 04, 2023

Copy link to clipboard

Copied

@Stephen_A_Marsh Hi stephen, hope all is well,

I've been trying to incorporate your suggestion to my script but something seems to not be working properly. So, It does target the solid color layer and it allows me to edit it with the color picker, but cant make it update live the color of the layer as I move the color picker accross different colors in the document, as it does when you click on the solid color fill thumbnail layer.

Here is the code i have. Can you check the function updateColorFillLayer and pickColor please? something may be off. If its too much of an ask, i;d understand. Cheers! but honestly, seriously looking forward to make this happen on this code...

function main() {
    var psdFolder = Folder.selectDialog("Select the folder containing PSD files:");
    var imgFolder = Folder.selectDialog("Select the folder containing image files:");
    var exportFolder = Folder.selectDialog("Select the folder for exported files:");

    if (!psdFolder || !imgFolder || !exportFolder) {
        alert("No folder selected. Exiting...");
        return;
    }

    var psdFiles = psdFolder.getFiles("*.psd");
    var imgFiles = imgFolder.getFiles(/\.(jpg|jpeg|png|tif|tiff|bmp|gif)$/i);

    for (var i = 0; i < psdFiles.length; i++) {
        var psdFile = psdFiles[i];
        var doc = open(psdFile);

        var colorFillLayer = findLayerByName(doc, "color");

        for (var j = 0; j < imgFiles.length; j++) {
            var imgFile = imgFiles[j];

            // Find both smart object layers
            var layerVertical = findLayerByName(doc, "smart_object_vertical");
            var layerSquare = findLayerByName(doc, "smart_object_square");

            // Calculate aspect ratio
            var aspectRatio = getImageAspectRatio(imgFile);

            // Choose the appropriate smart object layer based on the aspect ratio
            var layerName = aspectRatio < 1 ? "smart_object_vertical" : "smart_object_square";

            // Set the visibility of both layers accordingly
            if (layerName === "smart_object_vertical") {
                layerVertical.visible = true;
                layerSquare.visible = false;
            } else {
                layerVertical.visible = false;
                layerSquare.visible = true;
            }

            var layer = findLayerByName(doc, layerName);
            if (layer) {
                replaceSmartObjectContent(doc, layer, imgFile);
            }

            // Pick the color and update the color fill layer
            var pickedColor = pickColor();
            if (pickedColor) {
                updateColorFillLayer(doc, colorFillLayer, pickedColor);
            }

            var fileName = psdFile.name.replace(".psd", "_" + imgFile.name);
            var saveFile = new File(exportFolder + "/" + fileName);

            // Check if the image has been processed already to not process again in the same folder
            if (saveFile.exists) {
                continue;
            }

            setDocumentResolution(doc, 300);
            saveAsPNG(doc, saveFile);
        }

        // Close the document and don't save changes
        doc.close(SaveOptions.DONOTSAVECHANGES);
    }
}

function getImageAspectRatio(file) {
    var tempDoc = open(file);
    var aspectRatio = tempDoc.width / tempDoc.height;
    tempDoc.close(SaveOptions.DONOTSAVECHANGES);
    return aspectRatio;
}

function setDocumentResolution(doc, resolution) {
    var originalRulerUnits = app.preferences.rulerUnits;
    app.preferences.rulerUnits = Units.PIXELS;

    var originalWidth = doc.width;
    var originalHeight = doc.height;
    var resampleMethod = ResampleMethod.AUTOMATIC;
    doc.resizeImage(originalWidth, originalHeight, resolution, resampleMethod);

    app.preferences.rulerUnits = originalRulerUnits;
}


function findLayerByName(doc, name, layerSet) {
    if (!layerSet) layerSet = doc.layers;
    
    for (var i = 0; i < layerSet.length; i++) {
        var layer = layerSet[i];
        if (layer.name === name) {
            return layer;
        }
        if (layer.typename === "LayerSet") {
            var foundLayer = findLayerByName(doc, name, layer.layers);
            if (foundLayer) {
                return foundLayer;
            }
        }
    }
    return null;
}





function updateColorFillLayer(doc, colorFillLayer, fillColor) {
    var activeLayer = doc.activeLayer;
    doc.activeLayer = colorFillLayer;

    function s2t(s) {
        return app.stringIDToTypeID(s);
    }

    

    var descriptor = new ActionDescriptor();
    var descriptor2 = new ActionDescriptor();
    var descriptor3 = new ActionDescriptor();
    var reference = new ActionReference();

    reference.putEnumerated(s2t("contentLayer"), s2t("ordinal"), s2t("targetEnum"));
    descriptor.putReference(s2t("null"), reference);

    descriptor3.putDouble(s2t("red"), fillColor.rgb.red);
    descriptor3.putDouble(s2t("grain"), fillColor.rgb.green);
    descriptor3.putDouble(s2t("blue"), fillColor.rgb.blue);

    descriptor2.putObject(s2t("color"), s2t("RGBColor"), descriptor3);
    descriptor.putObject(s2t("to"), s2t("solidColorLayer"), descriptor2);

    executeAction(s2t("set"), descriptor, DialogModes.NO);

    doc.activeLayer = activeLayer;
}



function saveAsPNG(doc, saveFile) {
var pngOptions = new PNGSaveOptions();
pngOptions.compression = 2; // Change this value to control the compression level (0-9)
pngOptions.interlaced = false;
doc.saveAs(saveFile, pngOptions, true, Extension.LOWERCASE);
}
function replaceSmartObjectContent(doc, layer, imgFile) {
    doc.activeLayer = layer;
    if (layer.kind === LayerKind.SMARTOBJECT) {
        var idplacedLayerReplaceContents = stringIDToTypeID("placedLayerReplaceContents");
        var desc = new ActionDescriptor();
        desc.putPath(charIDToTypeID("null"), imgFile);
        try {
            executeAction(idplacedLayerReplaceContents, desc, DialogModes.NO);
        } catch (e) {
            alert("Error: " + e.message);
        }
    } else {
        alert("The specified layer is not a Smart Object.");
    }
}


function pickColor() {
    // Check if the active layer is a Solid Color adjustment layer
    if (activeDocument.activeLayer.kind == LayerKind.SOLIDFILL) {
        // Get the current color of the Solid Color adjustment layer
        var currentColor = interactiveSetColorFill();

        // Set the initial color of the color picker to the current color
        app.foregroundColor.rgb.red = currentColor[0];
        app.foregroundColor.rgb.green = currentColor[1];
        app.foregroundColor.rgb.blue = currentColor[2];
    }

    var colorPicker = new Window("dialog", "Choose a color");
    colorPicker.orientation = "column";
    colorPicker.alignChildren = "left";

    var colorPickerPanel = colorPicker.add("panel", undefined, "Color");
    colorPickerPanel.alignment = "fill";
    colorPickerPanel.margins = 10;

    var colorPickerGroup = colorPickerPanel.add("group");
    colorPickerGroup.orientation = "row";
    colorPickerGroup.alignChildren = "center";
    colorPickerGroup.margins = 0;

    colorPickerGroup.add("statictext", undefined, "Current color:");
    var colorSample = colorPickerGroup.add("panel", undefined, "");
    colorSample.size = [40, 20];
    colorSample.graphics.backgroundColor = colorSample.graphics.newBrush(colorSample.graphics.BrushType.SOLID_COLOR, [app.foregroundColor.rgb.red / 255, app.foregroundColor.rgb.green / 255, app.foregroundColor.rgb.blue / 255]);

    colorPicker.add("button", undefined, "Choose color", {name: "ok"});
    colorPicker.add("button", undefined, "Cancel", {name: "cancel"});

    if (colorPicker.show() === 1) {
        app.showColorPicker();
        return app.foregroundColor;
    } else {
        return null;
    }
}
    

/*function pickColor() {
    var colorPicker = new Window("dialog", "Choose a color");
    colorPicker.orientation = "column";
    colorPicker.alignChildren = "left";

    var colorPickerPanel = colorPicker.add("panel", undefined, "Color");
    colorPickerPanel.alignment = "fill";
    colorPickerPanel.margins = 10;

    var colorPickerGroup = colorPickerPanel.add("group");
    colorPickerGroup.orientation = "row";
    colorPickerGroup.alignChildren = "center";
    colorPickerGroup.margins = 0;

    colorPickerGroup.add("statictext", undefined, "Current color:");
    var colorSample = colorPickerGroup.add("panel", undefined, "");
    colorSample.size = [40, 20];
    colorSample.graphics.backgroundColor = colorSample.graphics.newBrush(colorSample.graphics.BrushType.SOLID_COLOR, [app.foregroundColor.rgb.red / 255, app.foregroundColor.rgb.green / 255, app.foregroundColor.rgb.blue / 255]);

    colorPicker.add("button", undefined, "Choose color", {name: "ok"});
    colorPicker.add("button", undefined, "Cancel", {name: "cancel"});

    if (colorPicker.show() === 1) {
        app.showColorPicker();
        return app.foregroundColor;
    } else {
        return null;
    }
}
*/

main();

 

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
Explorer ,
Apr 04, 2023 Apr 04, 2023

Copy link to clipboard

Copied

@Stephen_A_Marsh Nevermind my friend. All is resolved now! thanks a lot. I managed to work with your suggestion and reading other forum posts. GG

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 ,
Apr 04, 2023 Apr 04, 2023

Copy link to clipboard

Copied

You're welcome, glad to help and that you worked it out!

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 ,
Jul 22, 2023 Jul 22, 2023

Copy link to clipboard

Copied

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
New Here ,
Aug 07, 2023 Aug 07, 2023

Copy link to clipboard

Copied

Hi @Stephen_A_Marsh . I am trying to use this code and take it one step further. I'd like to generate a random solid fill color do you know if this is possible? I've googled and ChatGPT'd myself in cicrles. 

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 ,
Aug 07, 2023 Aug 07, 2023

Copy link to clipboard

Copied

LATEST

Yes it's possible, I'll post the code later.

 

@Gabe24018510d39f – here is the link to the code:

 

 
// https://community.adobe.com/t5/photoshop-ecosystem-discussions/create-grid-rectangles-inside-selected-area-quot-bug-quot/td-p/10342770

// Add Random RGB Colour Solid Fill Layer.jsx

var randomSolidColor = new SolidColor();
var R = randomSolidColor.rgb.red = Math.round(Math.random() * 255);
var G = randomSolidColor.rgb.green = Math.round(Math.random() * 255);
var B = randomSolidColor.rgb.blue = Math.round(Math.random() * 255);

makeRandomFill(R, G, B);

// Rename Solid Fill Layer to RGB Values.jsx
// https://community.adobe.com/t5/photoshop-ecosystem-discussions/how-to-get-the-fill-color-of-shape-or-solid-color-fill-layers/m-p/5294969
// Modified by Stephen_A_Marsh, based on code by C.Pfaffenbichler, based on code by the late Michael L Hale

/*
if (app.activeDocument.activeLayer.kind == LayerKind.SOLIDFILL) {
*/
    var ref = new ActionReference();
    ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
    var layerDesc = executeActionGet(ref);
    var adjList = layerDesc.getList(stringIDToTypeID('adjustment'));
    var theColors = adjList.getObjectValue(0).getObjectValue(stringIDToTypeID('color'));
    // ~~ = round down to 0-255 integer
    var red256Value = ~~theColors.getUnitDoubleValue(theColors.getKey(0));
    var green256Value = ~~theColors.getUnitDoubleValue(theColors.getKey(1));
    var blue256Value = ~~theColors.getUnitDoubleValue(theColors.getKey(2));
    // Create layer name variables
    var red256Value = "R: 00" + red256Value;
    var red256Value = red256Value.replace(/(^.{3})(\d+)(\d{3}$)/, '$1$3');
    var green256Value = "G: 00" + green256Value;
    var green256Value = green256Value.replace(/(^.{3})(\d+)(\d{3}$)/, '$1$3');
    var blue256Value = "B: 00" + blue256Value;
    var blue256Value = blue256Value.replace(/(^.{3})(\d+)(\d{3}$)/, '$1$3');
    // Rename the active layer from the color fill values
    var layerNameFromFill = red256Value + " " + green256Value + " " + blue256Value;
    app.activeDocument.activeLayer.name = layerNameFromFill;
/*
}
else {
    alert("The active layer is not a Solid Fill layer!")
}
*/

function makeRandomFill(red, Grn, blue) {
    // Adds solid color adjustment layer
    var c2t = function (s) {
        return app.charIDToTypeID(s);
    };
    var s2t = function (s) {
        return app.stringIDToTypeID(s);
    };
    var descriptor = new ActionDescriptor();
    var descriptor2 = new ActionDescriptor();
    var descriptor3 = new ActionDescriptor();
    var descriptor4 = new ActionDescriptor();
    var reference = new ActionReference();
    reference.putClass(s2t("contentLayer"));
    descriptor.putReference(c2t("null"), reference);
    descriptor4.putDouble(s2t("red"), red);
    descriptor4.putDouble(c2t("Grn "), Grn);
    descriptor4.putDouble(s2t("blue"), blue);
    descriptor3.putObject(s2t("color"), s2t("RGBColor"), descriptor4);
    descriptor2.putObject(s2t("type"), s2t("solidColorLayer"), descriptor3);
    descriptor.putObject(s2t("using"), s2t("contentLayer"), descriptor2);
    executeAction(s2t("make"), descriptor, DialogModes.NO);
}

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