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

Create Grid Rectangles inside selected area ("BUG")

Engaged ,
Jan 31, 2019 Jan 31, 2019

Copy link to clipboard

Copied

Hello!

I found in this old post a very useful script written and updated by the brilliant Chuck Uebele

Re: Create Grid Rectangles inside selected area

I decided to create a simple user interface, with row controllers, columns and the size of the space between rows and columns, only today that I noticed an unpleasant failure when the number of rows is different from the amount of columns.

Chuck Uebele, could you check out this video?

Could it be possible to circumvent this failure?

Here is the project as it was last updated:

https://pastebin.com/raw/xQ6ewGnn

Any help is valid! Thank you

TOPICS
Actions and scripting

Views

1.7K

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 , Jan 31, 2019 Jan 31, 2019

In line 16, the original script had row as the last variable. It needs to be column. Same with line 17, but it should be row. The below script works.

#target photoshop 

 

var row = 2;   

var column = 3;   

var lineSize = 15  //new

app.preferences.rulerUnits = Units.PIXELS; //new

 

if(app.documents.length>0){ 

    var doc = activeDocument; 

    try{ 

        var sBounds = doc.selection.bounds; 

        var lineAdjW = lineSize/row

        var lineAdjH = lineSize/column

         

        var sWidth = (

...

Votes

Translate

Translate
Adobe
Community Expert ,
Jan 31, 2019 Jan 31, 2019

Copy link to clipboard

Copied

When I wrote that code, I just made it work with equal number of columns of rows and numbers. So I used the row variable for calculating the columns, so you need to change that.

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 ,
Jan 31, 2019 Jan 31, 2019

Copy link to clipboard

Copied

It is essential that there be spaces between rows and columns, I also need to fit correctly in the selection when when row and column amount are different. It is possible? How do I fix it?

Thank you

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 ,
Jan 31, 2019 Jan 31, 2019

Copy link to clipboard

Copied

In line 16, the original script had row as the last variable. It needs to be column. Same with line 17, but it should be row. The below script works.

#target photoshop 

 

var row = 2;   

var column = 3;   

var lineSize = 15  //new

app.preferences.rulerUnits = Units.PIXELS; //new

 

if(app.documents.length>0){ 

    var doc = activeDocument; 

    try{ 

        var sBounds = doc.selection.bounds; 

        var lineAdjW = lineSize/row

        var lineAdjH = lineSize/column

         

        var sWidth = (parseFloat(sBounds[2]) -parseFloat(sBounds[0]))/column - lineSize + lineSize/(column );  //modified

        var sHeight = (parseFloat(sBounds[3]) -parseFloat(sBounds[1]))/row - lineSize + lineSize/(row ) ;  //modified

       

        var leftSide = parseFloat (sBounds[0]); 

        var topSide = parseFloat (sBounds[1]); 

      

        for(var i=0;i<row;i++){ 

            leftSide = parseFloat (sBounds[0]); 

            for(var j=0;j<column;j++){ 

                Create_Rectangle (topSide, leftSide, topSide + sHeight, leftSide + sWidth)  //old code

                leftSide += sWidth + lineSize

                } 

            topSide += sHeight  +lineSize

            } 

         

        }//end try  

    catch(e){alert('There is no selection')} 

    } 

else{alert('There are no open documents')} 

 

 

 

 

function Create_Rectangle(top,left,bottom,right) {   

var idMk = charIDToTypeID( "Mk  " ); 

    var desc14 = new ActionDescriptor(); 

    var idnull = charIDToTypeID( "null" ); 

        var ref4 = new ActionReference(); 

        var idcontentLayer = stringIDToTypeID( "contentLayer" ); 

        ref4.putClass( idcontentLayer ); 

    desc14.putReference( idnull, ref4 ); 

    var idUsng = charIDToTypeID( "Usng" ); 

        var desc15 = new ActionDescriptor(); 

        var idType = charIDToTypeID( "Type" ); 

            var desc16 = new ActionDescriptor(); 

            var idClr = charIDToTypeID( "Clr " ); 

                var desc17 = new ActionDescriptor(); 

                var idRd = charIDToTypeID( "Rd  " ); 

                desc17.putDouble( idRd, 0.000000 ); 

                var idGrn = charIDToTypeID( "Grn " ); 

                desc17.putDouble( idGrn, 0.000000 ); 

                var idBl = charIDToTypeID( "Bl  " ); 

                desc17.putDouble( idBl, 0.000000 ); 

            var idRGBC = charIDToTypeID( "RGBC" ); 

            desc16.putObject( idClr, idRGBC, desc17 ); 

        var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" ); 

        desc15.putObject( idType, idsolidColorLayer, desc16 ); 

        var idShp = charIDToTypeID( "Shp " ); 

            var desc18 = new ActionDescriptor(); 

            var idunitValueQuadVersion = stringIDToTypeID( "unitValueQuadVersion" ); 

            desc18.putInteger( idunitValueQuadVersion, 1 ); 

            var idTop = charIDToTypeID( "Top " ); 

            var idPxl = charIDToTypeID( "#Pxl" ); 

            desc18.putUnitDouble( idTop, idPxl, top ); 

            var idLeft = charIDToTypeID( "Left" ); 

            var idPxl = charIDToTypeID( "#Pxl" ); 

            desc18.putUnitDouble( idLeft, idPxl, left ); 

            var idBtom = charIDToTypeID( "Btom" ); 

            var idPxl = charIDToTypeID( "#Pxl" ); 

            desc18.putUnitDouble( idBtom, idPxl, bottom ); 

            var idRght = charIDToTypeID( "Rght" ); 

            var idPxl = charIDToTypeID( "#Pxl" ); 

            desc18.putUnitDouble( idRght, idPxl, right ); 

            var idtopRight = stringIDToTypeID( "topRight" ); 

            var idPxl = charIDToTypeID( "#Pxl" ); 

            desc18.putUnitDouble( idtopRight, idPxl, 0.000000 ); 

            var idtopLeft = stringIDToTypeID( "topLeft" ); 

            var idPxl = charIDToTypeID( "#Pxl" ); 

            desc18.putUnitDouble( idtopLeft, idPxl, 0.000000 ); 

            var idbottomLeft = stringIDToTypeID( "bottomLeft" ); 

            var idPxl = charIDToTypeID( "#Pxl" ); 

            desc18.putUnitDouble( idbottomLeft, idPxl, 0.000000 ); 

            var idbottomRight = stringIDToTypeID( "bottomRight" ); 

            var idPxl = charIDToTypeID( "#Pxl" ); 

            desc18.putUnitDouble( idbottomRight, idPxl, 0.000000 ); 

        var idRctn = charIDToTypeID( "Rctn" ); 

        desc15.putObject( idShp, idRctn, desc18 ); 

        var idstrokeStyle = stringIDToTypeID( "strokeStyle" ); 

            var desc19 = new ActionDescriptor(); 

            var idstrokeStyleVersion = stringIDToTypeID( "strokeStyleVersion" ); 

            desc19.putInteger( idstrokeStyleVersion, 2 ); 

            var idstrokeEnabled = stringIDToTypeID( "strokeEnabled" ); 

            desc19.putBoolean( idstrokeEnabled, true ); 

            var idfillEnabled = stringIDToTypeID( "fillEnabled" ); 

            desc19.putBoolean( idfillEnabled, true ); 

            var idstrokeStyleLineWidth = stringIDToTypeID( "strokeStyleLineWidth" ); 

            var idPxl = charIDToTypeID( "#Pxl" ); 

            desc19.putUnitDouble( idstrokeStyleLineWidth, idPxl, 1.000000 ); 

            var idstrokeStyleLineDashOffset = stringIDToTypeID( "strokeStyleLineDashOffset" ); 

            var idPnt = charIDToTypeID( "#Pnt" ); 

            desc19.putUnitDouble( idstrokeStyleLineDashOffset, idPnt, 0.000000 ); 

            var idstrokeStyleMiterLimit = stringIDToTypeID( "strokeStyleMiterLimit" ); 

            desc19.putDouble( idstrokeStyleMiterLimit, 100.000000 ); 

            var idstrokeStyleLineCapType = stringIDToTypeID( "strokeStyleLineCapType" ); 

            var idstrokeStyleLineCapType = stringIDToTypeID( "strokeStyleLineCapType" ); 

            var idstrokeStyleButtCap = stringIDToTypeID( "strokeStyleButtCap" ); 

            desc19.putEnumerated( idstrokeStyleLineCapType, idstrokeStyleLineCapType, idstrokeStyleButtCap ); 

            var idstrokeStyleLineJoinType = stringIDToTypeID( "strokeStyleLineJoinType" ); 

            var idstrokeStyleLineJoinType = stringIDToTypeID( "strokeStyleLineJoinType" ); 

            var idstrokeStyleMiterJoin = stringIDToTypeID( "strokeStyleMiterJoin" ); 

            desc19.putEnumerated( idstrokeStyleLineJoinType, idstrokeStyleLineJoinType, idstrokeStyleMiterJoin ); 

            var idstrokeStyleLineAlignment = stringIDToTypeID( "strokeStyleLineAlignment" ); 

            var idstrokeStyleLineAlignment = stringIDToTypeID( "strokeStyleLineAlignment" ); 

            var idstrokeStyleAlignInside = stringIDToTypeID( "strokeStyleAlignInside" ); 

            desc19.putEnumerated( idstrokeStyleLineAlignment, idstrokeStyleLineAlignment, idstrokeStyleAlignInside ); 

            var idstrokeStyleScaleLock = stringIDToTypeID( "strokeStyleScaleLock" ); 

            desc19.putBoolean( idstrokeStyleScaleLock, false ); 

            var idstrokeStyleStrokeAdjust = stringIDToTypeID( "strokeStyleStrokeAdjust" ); 

            desc19.putBoolean( idstrokeStyleStrokeAdjust, false ); 

            var idstrokeStyleLineDashSet = stringIDToTypeID( "strokeStyleLineDashSet" ); 

                var list2 = new ActionList(); 

            desc19.putList( idstrokeStyleLineDashSet, list2 ); 

            var idstrokeStyleBlendMode = stringIDToTypeID( "strokeStyleBlendMode" ); 

            var idBlnM = charIDToTypeID( "BlnM" ); 

            var idNrml = charIDToTypeID( "Nrml" ); 

            desc19.putEnumerated( idstrokeStyleBlendMode, idBlnM, idNrml ); 

            var idstrokeStyleOpacity = stringIDToTypeID( "strokeStyleOpacity" ); 

            var idPrc = charIDToTypeID( "#Prc" ); 

            desc19.putUnitDouble( idstrokeStyleOpacity, idPrc, 100.000000 ); 

            var idstrokeStyleContent = stringIDToTypeID( "strokeStyleContent" ); 

                var desc20 = new ActionDescriptor(); 

                var idClr = charIDToTypeID( "Clr " ); 

                    var desc21 = new ActionDescriptor(); 

                    var idRd = charIDToTypeID( "Rd  " ); 

                    desc21.putDouble( idRd, 121.991998 ); 

                    var idGrn = charIDToTypeID( "Grn " ); 

                    desc21.putDouble( idGrn, 121.991998 ); 

                    var idBl = charIDToTypeID( "Bl  " ); 

                    desc21.putDouble( idBl, 121.991998 ); 

                var idRGBC = charIDToTypeID( "RGBC" ); 

                desc20.putObject( idClr, idRGBC, desc21 ); 

            var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" ); 

            desc19.putObject( idstrokeStyleContent, idsolidColorLayer, desc20 ); 

            var idstrokeStyleResolution = stringIDToTypeID( "strokeStyleResolution" ); 

            desc19.putDouble( idstrokeStyleResolution, 300.000000 ); 

        var idstrokeStyle = stringIDToTypeID( "strokeStyle" ); 

        desc15.putObject( idstrokeStyle, idstrokeStyle, desc19 ); 

    var idcontentLayer = stringIDToTypeID( "contentLayer" ); 

    desc14.putObject( idUsng, idcontentLayer, desc15 ); 

    var idLyrI = charIDToTypeID( "LyrI" ); 

    desc14.putInteger( idLyrI, 27 ); 

executeAction( idMk, desc14, 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
Engaged ,
Jan 31, 2019 Jan 31, 2019

Copy link to clipboard

Copied

What a fright! Good thing it worked perfectly well now ... I'm very grateful to you one more time Chuck Uebele

Thank you.

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 Beginner ,
Jan 07, 2022 Jan 07, 2022

Copy link to clipboard

Copied

IF EVERY BOX IN DIFFERENT COLOR ,HOW IS POSIBLE ?

PLEASE SOLUTION

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 ,
Jan 07, 2022 Jan 07, 2022

Copy link to clipboard

Copied


@zia5E08 wrote:

IF EVERY BOX IN DIFFERENT COLOR ,HOW IS POSIBLE ?

PLEASE SOLUTION


 

 

I would use a random fill colour.

 

The following code will generate a new Solid Color Adjustment Layer with a random RGB fill colour.  It is then just adapting the existing code to do similar...

 

var randomSolidColor = new SolidColor();
var red = randomSolidColor.rgb.red = Math.round(Math.random() * 255);
var Grn = randomSolidColor.rgb.green = Math.round(Math.random() * 255);
var blue = randomSolidColor.rgb.blue = Math.round(Math.random() * 255);
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
Community Expert ,
Jan 07, 2022 Jan 07, 2022

Copy link to clipboard

Copied

 

Update: This related but different script renames the active solid fill layer to the random RGB values, it could be incorporated into the other scripts discussed if required:

 

// 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 to nearest integer
    var red256Value = Math.round(theColors.getUnitDoubleValue(theColors.getKey(0)));
    var green256Value = Math.round(theColors.getUnitDoubleValue(theColors.getKey(1)));
    var blue256Value = Math.round(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!")
}

 

 

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 ,
Jan 07, 2022 Jan 07, 2022

Copy link to clipboard

Copied

 

Here is the modified code from the pastebin site, with the GUI:

 

dlg=new Window("dialog","My dialog", { x: 0, y:0,  width: 370,  height:130});    
var gp_conteudo = dlg.add("group", {x:5, y:0, width:250, height:600}); 
var pn_Config = gp_conteudo.add("panel", {x:13, y:20, width:234,height:95}, "configure project"); 

Ro = pn_Config.add("edittext", {x:40, y:18, width:20, height:20}, " 3");
Col= pn_Config.add("edittext", {x:72, y:18, width:20, height:20}, " 3");
Lin =pn_Config.add("edittext", {x:147, y:18, width:27, height:20}, " 15");

txts = pn_Config.add("statictext", {x:10, y:22, width:280, height:15}, " row                         column              lineSize");

exec= dlg.add("button", {x:260, y:18, width:100,height:25}, "Execut", { name: "ok"});
Canc = dlg.add("button", {x:260, y:50, width:100,height:25}, "Cancel");


exec.onClick = function() { 
 dlg.close();
 configure();  
 
 }



dlg.center();
dlg.show()

function configure() {  

var row = Number(Ro.text);
var column = Number(Col.text);
var lineSize = Number(Lin.text);  
  
app.preferences.rulerUnits = Units.PIXELS; //new  
    
if(app.documents.length>0){    
    var doc = activeDocument;    
    try{    
        var sBounds = doc.selection.bounds;    
        var lineAdjW = lineSize/row  
        var lineAdjH = lineSize/column  
            
        var sWidth = (parseFloat(sBounds[2]) -parseFloat(sBounds[0]))/column - lineSize + lineSize/(row );  //modified  
        var sHeight = (parseFloat(sBounds[3]) -parseFloat(sBounds[1]))/row - lineSize + lineSize/(column ) ;  //modified  
          
        var leftSide = parseFloat (sBounds[0]);    
        var topSide = parseFloat (sBounds[1]);    
         
        for(var i=0;i<row;i++){    
            leftSide = parseFloat (sBounds[0]);    
            for(var j=0;j<column;j++){    
                Create_Rectangle (topSide, leftSide, topSide + sHeight, leftSide + sWidth)  //old code  
                leftSide += sWidth + lineSize  
                }    
            topSide += sHeight  +lineSize  
            }    
            
        }//end try     
    catch(e){alert('There is no selection')}    
    }    
else{alert('There are no open documents')}    
    
    
    
    
function Create_Rectangle(top, left, bottom, right) { 
var randomSolidColor = new SolidColor();
var idMk = charIDToTypeID( "Mk  " );    
    var desc14 = new ActionDescriptor();    
    var idnull = charIDToTypeID( "null" );    
        var ref4 = new ActionReference();    
        var idcontentLayer = stringIDToTypeID( "contentLayer" );    
        ref4.putClass( idcontentLayer );    
    desc14.putReference( idnull, ref4 );    
    var idUsng = charIDToTypeID( "Usng" );    
        var desc15 = new ActionDescriptor();    
        var idType = charIDToTypeID( "Type" );    
            var desc16 = new ActionDescriptor();    
            var idClr = charIDToTypeID( "Clr " );    
                var desc17 = new ActionDescriptor();    
                var idRd = charIDToTypeID( "Rd  " );    
                //desc17.putDouble( idRd, 0.000000 ); 
                // Random
                desc17.putDouble(idRd, randomSolidColor.rgb.red = Math.round(Math.random() * 255));
                var idGrn = charIDToTypeID( "Grn " );    
                //desc17.putDouble( idGrn, 0.000000 ); 
                // Random
                desc17.putDouble(idGrn, randomSolidColor.rgb.green = Math.round(Math.random() * 255));
                var idBl = charIDToTypeID( "Bl  " );    
                //desc17.putDouble( idBl, 0.000000 );
                // Random
                desc17.putDouble(idBl, randomSolidColor.rgb.blue = Math.round(Math.random() * 255));
            var idRGBC = charIDToTypeID( "RGBC" );    
            desc16.putObject( idClr, idRGBC, desc17 );    
        var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );    
        desc15.putObject( idType, idsolidColorLayer, desc16 );    
        var idShp = charIDToTypeID( "Shp " );    
            var desc18 = new ActionDescriptor();    
            var idunitValueQuadVersion = stringIDToTypeID( "unitValueQuadVersion" );    
            desc18.putInteger( idunitValueQuadVersion, 1 );    
            var idTop = charIDToTypeID( "Top " );    
            var idPxl = charIDToTypeID( "#Pxl" );    
            desc18.putUnitDouble( idTop, idPxl, top );    
            var idLeft = charIDToTypeID( "Left" );    
            var idPxl = charIDToTypeID( "#Pxl" );    
            desc18.putUnitDouble( idLeft, idPxl, left );    
            var idBtom = charIDToTypeID( "Btom" );    
            var idPxl = charIDToTypeID( "#Pxl" );    
            desc18.putUnitDouble( idBtom, idPxl, bottom );    
            var idRght = charIDToTypeID( "Rght" );    
            var idPxl = charIDToTypeID( "#Pxl" );    
            desc18.putUnitDouble( idRght, idPxl, right );    
            var idtopRight = stringIDToTypeID( "topRight" );    
            var idPxl = charIDToTypeID( "#Pxl" );    
            desc18.putUnitDouble( idtopRight, idPxl, 0.000000 );    
            var idtopLeft = stringIDToTypeID( "topLeft" );    
            var idPxl = charIDToTypeID( "#Pxl" );    
            desc18.putUnitDouble( idtopLeft, idPxl, 0.000000 );    
            var idbottomLeft = stringIDToTypeID( "bottomLeft" );    
            var idPxl = charIDToTypeID( "#Pxl" );    
            desc18.putUnitDouble( idbottomLeft, idPxl, 0.000000 );    
            var idbottomRight = stringIDToTypeID( "bottomRight" );    
            var idPxl = charIDToTypeID( "#Pxl" );    
            desc18.putUnitDouble( idbottomRight, idPxl, 0.000000 );    
        var idRctn = charIDToTypeID( "Rctn" );    
        desc15.putObject( idShp, idRctn, desc18 );    
        var idstrokeStyle = stringIDToTypeID( "strokeStyle" );    
            var desc19 = new ActionDescriptor();    
            var idstrokeStyleVersion = stringIDToTypeID( "strokeStyleVersion" );    
            desc19.putInteger( idstrokeStyleVersion, 2 );    
            var idstrokeEnabled = stringIDToTypeID( "strokeEnabled" );    
            desc19.putBoolean( idstrokeEnabled, true );    
            var idfillEnabled = stringIDToTypeID( "fillEnabled" );    
            desc19.putBoolean( idfillEnabled, true );    
            var idstrokeStyleLineWidth = stringIDToTypeID( "strokeStyleLineWidth" );    
            var idPxl = charIDToTypeID( "#Pxl" );    
            desc19.putUnitDouble( idstrokeStyleLineWidth, idPxl, 1.000000 );    
            var idstrokeStyleLineDashOffset = stringIDToTypeID( "strokeStyleLineDashOffset" );    
            var idPnt = charIDToTypeID( "#Pnt" );    
            desc19.putUnitDouble( idstrokeStyleLineDashOffset, idPnt, 0.000000 );    
            var idstrokeStyleMiterLimit = stringIDToTypeID( "strokeStyleMiterLimit" );    
            desc19.putDouble( idstrokeStyleMiterLimit, 100.000000 );    
            var idstrokeStyleLineCapType = stringIDToTypeID( "strokeStyleLineCapType" );    
            var idstrokeStyleLineCapType = stringIDToTypeID( "strokeStyleLineCapType" );    
            var idstrokeStyleButtCap = stringIDToTypeID( "strokeStyleButtCap" );    
            desc19.putEnumerated( idstrokeStyleLineCapType, idstrokeStyleLineCapType, idstrokeStyleButtCap );    
            var idstrokeStyleLineJoinType = stringIDToTypeID( "strokeStyleLineJoinType" );    
            var idstrokeStyleLineJoinType = stringIDToTypeID( "strokeStyleLineJoinType" );    
            var idstrokeStyleMiterJoin = stringIDToTypeID( "strokeStyleMiterJoin" );    
            desc19.putEnumerated( idstrokeStyleLineJoinType, idstrokeStyleLineJoinType, idstrokeStyleMiterJoin );    
            var idstrokeStyleLineAlignment = stringIDToTypeID( "strokeStyleLineAlignment" );    
            var idstrokeStyleLineAlignment = stringIDToTypeID( "strokeStyleLineAlignment" );    
            var idstrokeStyleAlignInside = stringIDToTypeID( "strokeStyleAlignInside" );    
            desc19.putEnumerated( idstrokeStyleLineAlignment, idstrokeStyleLineAlignment, idstrokeStyleAlignInside );    
            var idstrokeStyleScaleLock = stringIDToTypeID( "strokeStyleScaleLock" );    
            desc19.putBoolean( idstrokeStyleScaleLock, false );    
            var idstrokeStyleStrokeAdjust = stringIDToTypeID( "strokeStyleStrokeAdjust" );    
            desc19.putBoolean( idstrokeStyleStrokeAdjust, false );    
            var idstrokeStyleLineDashSet = stringIDToTypeID( "strokeStyleLineDashSet" );    
                var list2 = new ActionList();    
            desc19.putList( idstrokeStyleLineDashSet, list2 );    
            var idstrokeStyleBlendMode = stringIDToTypeID( "strokeStyleBlendMode" );    
            var idBlnM = charIDToTypeID( "BlnM" );    
            var idNrml = charIDToTypeID( "Nrml" );    
            desc19.putEnumerated( idstrokeStyleBlendMode, idBlnM, idNrml );    
            var idstrokeStyleOpacity = stringIDToTypeID( "strokeStyleOpacity" );    
            var idPrc = charIDToTypeID( "#Prc" );    
            desc19.putUnitDouble( idstrokeStyleOpacity, idPrc, 100.000000 );    
            var idstrokeStyleContent = stringIDToTypeID( "strokeStyleContent" );    
                var desc20 = new ActionDescriptor();    
                var idClr = charIDToTypeID( "Clr " );    
                    var desc21 = new ActionDescriptor();    
                    var idRd = charIDToTypeID( "Rd  " );    
                    desc21.putDouble( idRd, 121.991998 );    
                    var idGrn = charIDToTypeID( "Grn " );    
                    desc21.putDouble( idGrn, 121.991998 );    
                    var idBl = charIDToTypeID( "Bl  " );    
                    desc21.putDouble( idBl, 121.991998 );    
                var idRGBC = charIDToTypeID( "RGBC" );    
                desc20.putObject( idClr, idRGBC, desc21 );    
            var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );    
            desc19.putObject( idstrokeStyleContent, idsolidColorLayer, desc20 );    
            var idstrokeStyleResolution = stringIDToTypeID( "strokeStyleResolution" );    
            desc19.putDouble( idstrokeStyleResolution, 300.000000 );    
        var idstrokeStyle = stringIDToTypeID( "strokeStyle" );    
        desc15.putObject( idstrokeStyle, idstrokeStyle, desc19 );    
    var idcontentLayer = stringIDToTypeID( "contentLayer" );    
    desc14.putObject( idUsng, idcontentLayer, desc15 );    
    var idLyrI = charIDToTypeID( "LyrI" );    
    desc14.putInteger( idLyrI, 27 );    
executeAction( idMk, desc14, DialogModes.NO );    
    };
 
}

 

 

 

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

 

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 ,
Jan 07, 2022 Jan 07, 2022

Copy link to clipboard

Copied

 

Here is the random colour applied to Chuck's script, without the GUI:

 

#target photoshop  
  
var row = 2;    
var column = 3;    
var lineSize = 15  //new
app.preferences.rulerUnits = Units.PIXELS; //new
  
if(app.documents.length>0){  
    var doc = activeDocument;  
    try{  
        var sBounds = doc.selection.bounds;  
        var lineAdjW = lineSize/row
        var lineAdjH = lineSize/column
          
        var sWidth = (parseFloat(sBounds[2]) -parseFloat(sBounds[0]))/column - lineSize + lineSize/(column );  //modified
        var sHeight = (parseFloat(sBounds[3]) -parseFloat(sBounds[1]))/row - lineSize + lineSize/(row ) ;  //modified
        
        var leftSide = parseFloat (sBounds[0]);  
        var topSide = parseFloat (sBounds[1]);  
       
        for(var i=0;i<row;i++){  
            leftSide = parseFloat (sBounds[0]);  
            for(var j=0;j<column;j++){  
                Create_Rectangle (topSide, leftSide, topSide + sHeight, leftSide + sWidth)  //old code
                leftSide += sWidth + lineSize
                }  
            topSide += sHeight  +lineSize
            }  
          
        }//end try   
    catch(e){alert('There is no selection')}  
    }  
else{alert('There are no open documents')}  
  
  
  
  
function Create_Rectangle(top, left, bottom, right) {   
var randomSolidColor = new SolidColor();
var idMk = charIDToTypeID( "Mk  " );    
    var desc14 = new ActionDescriptor();    
    var idnull = charIDToTypeID( "null" );    
        var ref4 = new ActionReference();    
        var idcontentLayer = stringIDToTypeID( "contentLayer" );    
        ref4.putClass( idcontentLayer );    
    desc14.putReference( idnull, ref4 );    
    var idUsng = charIDToTypeID( "Usng" );    
        var desc15 = new ActionDescriptor();    
        var idType = charIDToTypeID( "Type" );    
            var desc16 = new ActionDescriptor();    
            var idClr = charIDToTypeID( "Clr " );    
                var desc17 = new ActionDescriptor();    
                var idRd = charIDToTypeID( "Rd  " );    
                //desc17.putDouble( idRd, 0.000000 ); 
                // Random
                desc17.putDouble(idRd, randomSolidColor.rgb.red = Math.round(Math.random() * 255));
                var idGrn = charIDToTypeID( "Grn " );    
                //desc17.putDouble( idGrn, 0.000000 ); 
                // Random
                desc17.putDouble(idGrn, randomSolidColor.rgb.green = Math.round(Math.random() * 255));
                var idBl = charIDToTypeID( "Bl  " );    
                //desc17.putDouble( idBl, 0.000000 );
                // Random
                desc17.putDouble(idBl, randomSolidColor.rgb.blue = Math.round(Math.random() * 255));
            var idRGBC = charIDToTypeID( "RGBC" );    
            desc16.putObject( idClr, idRGBC, desc17 );    
        var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );    
        desc15.putObject( idType, idsolidColorLayer, desc16 );    
        var idShp = charIDToTypeID( "Shp " );    
            var desc18 = new ActionDescriptor();    
            var idunitValueQuadVersion = stringIDToTypeID( "unitValueQuadVersion" );    
            desc18.putInteger( idunitValueQuadVersion, 1 );    
            var idTop = charIDToTypeID( "Top " );    
            var idPxl = charIDToTypeID( "#Pxl" );    
            desc18.putUnitDouble( idTop, idPxl, top );    
            var idLeft = charIDToTypeID( "Left" );    
            var idPxl = charIDToTypeID( "#Pxl" );    
            desc18.putUnitDouble( idLeft, idPxl, left );    
            var idBtom = charIDToTypeID( "Btom" );    
            var idPxl = charIDToTypeID( "#Pxl" );    
            desc18.putUnitDouble( idBtom, idPxl, bottom );    
            var idRght = charIDToTypeID( "Rght" );    
            var idPxl = charIDToTypeID( "#Pxl" );    
            desc18.putUnitDouble( idRght, idPxl, right );    
            var idtopRight = stringIDToTypeID( "topRight" );    
            var idPxl = charIDToTypeID( "#Pxl" );    
            desc18.putUnitDouble( idtopRight, idPxl, 0.000000 );    
            var idtopLeft = stringIDToTypeID( "topLeft" );    
            var idPxl = charIDToTypeID( "#Pxl" );    
            desc18.putUnitDouble( idtopLeft, idPxl, 0.000000 );    
            var idbottomLeft = stringIDToTypeID( "bottomLeft" );    
            var idPxl = charIDToTypeID( "#Pxl" );    
            desc18.putUnitDouble( idbottomLeft, idPxl, 0.000000 );    
            var idbottomRight = stringIDToTypeID( "bottomRight" );    
            var idPxl = charIDToTypeID( "#Pxl" );    
            desc18.putUnitDouble( idbottomRight, idPxl, 0.000000 );    
        var idRctn = charIDToTypeID( "Rctn" );    
        desc15.putObject( idShp, idRctn, desc18 );    
        var idstrokeStyle = stringIDToTypeID( "strokeStyle" );    
            var desc19 = new ActionDescriptor();    
            var idstrokeStyleVersion = stringIDToTypeID( "strokeStyleVersion" );    
            desc19.putInteger( idstrokeStyleVersion, 2 );    
            var idstrokeEnabled = stringIDToTypeID( "strokeEnabled" );    
            desc19.putBoolean( idstrokeEnabled, true );    
            var idfillEnabled = stringIDToTypeID( "fillEnabled" );    
            desc19.putBoolean( idfillEnabled, true );    
            var idstrokeStyleLineWidth = stringIDToTypeID( "strokeStyleLineWidth" );    
            var idPxl = charIDToTypeID( "#Pxl" );    
            desc19.putUnitDouble( idstrokeStyleLineWidth, idPxl, 1.000000 );    
            var idstrokeStyleLineDashOffset = stringIDToTypeID( "strokeStyleLineDashOffset" );    
            var idPnt = charIDToTypeID( "#Pnt" );    
            desc19.putUnitDouble( idstrokeStyleLineDashOffset, idPnt, 0.000000 );    
            var idstrokeStyleMiterLimit = stringIDToTypeID( "strokeStyleMiterLimit" );    
            desc19.putDouble( idstrokeStyleMiterLimit, 100.000000 );    
            var idstrokeStyleLineCapType = stringIDToTypeID( "strokeStyleLineCapType" );    
            var idstrokeStyleLineCapType = stringIDToTypeID( "strokeStyleLineCapType" );    
            var idstrokeStyleButtCap = stringIDToTypeID( "strokeStyleButtCap" );    
            desc19.putEnumerated( idstrokeStyleLineCapType, idstrokeStyleLineCapType, idstrokeStyleButtCap );    
            var idstrokeStyleLineJoinType = stringIDToTypeID( "strokeStyleLineJoinType" );    
            var idstrokeStyleLineJoinType = stringIDToTypeID( "strokeStyleLineJoinType" );    
            var idstrokeStyleMiterJoin = stringIDToTypeID( "strokeStyleMiterJoin" );    
            desc19.putEnumerated( idstrokeStyleLineJoinType, idstrokeStyleLineJoinType, idstrokeStyleMiterJoin );    
            var idstrokeStyleLineAlignment = stringIDToTypeID( "strokeStyleLineAlignment" );    
            var idstrokeStyleLineAlignment = stringIDToTypeID( "strokeStyleLineAlignment" );    
            var idstrokeStyleAlignInside = stringIDToTypeID( "strokeStyleAlignInside" );    
            desc19.putEnumerated( idstrokeStyleLineAlignment, idstrokeStyleLineAlignment, idstrokeStyleAlignInside );    
            var idstrokeStyleScaleLock = stringIDToTypeID( "strokeStyleScaleLock" );    
            desc19.putBoolean( idstrokeStyleScaleLock, false );    
            var idstrokeStyleStrokeAdjust = stringIDToTypeID( "strokeStyleStrokeAdjust" );    
            desc19.putBoolean( idstrokeStyleStrokeAdjust, false );    
            var idstrokeStyleLineDashSet = stringIDToTypeID( "strokeStyleLineDashSet" );    
                var list2 = new ActionList();    
            desc19.putList( idstrokeStyleLineDashSet, list2 );    
            var idstrokeStyleBlendMode = stringIDToTypeID( "strokeStyleBlendMode" );    
            var idBlnM = charIDToTypeID( "BlnM" );    
            var idNrml = charIDToTypeID( "Nrml" );    
            desc19.putEnumerated( idstrokeStyleBlendMode, idBlnM, idNrml );    
            var idstrokeStyleOpacity = stringIDToTypeID( "strokeStyleOpacity" );    
            var idPrc = charIDToTypeID( "#Prc" );    
            desc19.putUnitDouble( idstrokeStyleOpacity, idPrc, 100.000000 );    
            var idstrokeStyleContent = stringIDToTypeID( "strokeStyleContent" );    
                var desc20 = new ActionDescriptor();    
                var idClr = charIDToTypeID( "Clr " );    
                    var desc21 = new ActionDescriptor();    
                    var idRd = charIDToTypeID( "Rd  " );    
                    desc21.putDouble( idRd, 121.991998 );    
                    var idGrn = charIDToTypeID( "Grn " );    
                    desc21.putDouble( idGrn, 121.991998 );    
                    var idBl = charIDToTypeID( "Bl  " );    
                    desc21.putDouble( idBl, 121.991998 );    
                var idRGBC = charIDToTypeID( "RGBC" );    
                desc20.putObject( idClr, idRGBC, desc21 );    
            var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );    
            desc19.putObject( idstrokeStyleContent, idsolidColorLayer, desc20 );    
            var idstrokeStyleResolution = stringIDToTypeID( "strokeStyleResolution" );    
            desc19.putDouble( idstrokeStyleResolution, 300.000000 );    
        var idstrokeStyle = stringIDToTypeID( "strokeStyle" );    
        desc15.putObject( idstrokeStyle, idstrokeStyle, desc19 );    
    var idcontentLayer = stringIDToTypeID( "contentLayer" );    
    desc14.putObject( idUsng, idcontentLayer, desc15 );    
    var idLyrI = charIDToTypeID( "LyrI" );    
    desc14.putInteger( idLyrI, 27 );    
executeAction( idMk, desc14, 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
Community Beginner ,
Jan 07, 2022 Jan 07, 2022

Copy link to clipboard

Copied

!there is no selection 

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 ,
Jan 07, 2022 Jan 07, 2022

Copy link to clipboard

Copied

Indeed, the script requires a selection to create grid rectangles inside selected area!

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
LEGEND ,
Jan 08, 2022 Jan 08, 2022

Copy link to clipboard

Copied

Put on top of script:

randomSolidColor = new SolidColor

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 ,
Jan 08, 2022 Jan 08, 2022

Copy link to clipboard

Copied

Thanks, yes I found that while typing my latest reply.

 

Strange that it is picked up and throws the debugger, while Photoshop didn't choke.

 

I had problems with the debugger in VS Code for so long, that I just got used to working without it... I have it working OK these days, but old habits die hard and I don't always run code that is apparently working OK through the debugger.

 

Lesson learned!

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 Beginner ,
Jan 08, 2022 Jan 08, 2022

Copy link to clipboard

Copied

THANKS ITS WORK  GREATMAN 

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 Beginner ,
Jan 07, 2022 Jan 07, 2022

Copy link to clipboard

Copied

error  there is no selection , 

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 ,
Jan 07, 2022 Jan 07, 2022

Copy link to clipboard

Copied

So make a rectangular marquee tool selection before running the script.

 

I don't understand your issue.

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 Beginner ,
Jan 08, 2022 Jan 08, 2022

Copy link to clipboard

Copied

45.jpg

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 ,
Jan 08, 2022 Jan 08, 2022

Copy link to clipboard

Copied

I obviously don't get that message, unless there is no selection active. With an active selection, the script works as intended.

 

Anybody else?

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 Beginner ,
Jan 08, 2022 Jan 08, 2022

Copy link to clipboard

Copied

please check your script 

red.jpg

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 ,
Jan 08, 2022 Jan 08, 2022

Copy link to clipboard

Copied

Have you tried directly in Photoshop without going through ESTK?

 

Script with GUI works fine (191 lines of code).

Script without GUI works as well (163 lines of code).

 

In both cases, no reported errors when run directly in Photoshop and the output is as expected.

 

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 Beginner ,
Jan 08, 2022 Jan 08, 2022

Copy link to clipboard

Copied

OKAY   I'll try

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 ,
Jan 08, 2022 Jan 08, 2022

Copy link to clipboard

Copied

I just tried in VS Code and you are correct, when debugging this error is triggered, when it isn't when the script is directly run in Photoshop.

 

Turns out I forgot to paste in 1 line of code! :]

 

I declared a variable name that was referenced in the three random colours, but it was not defined.

 

I have now added in the missing line to the previous posts:

 

var randomSolidColor = new SolidColor();

 

Thank you!

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 Beginner ,
Jan 08, 2022 Jan 08, 2022

Copy link to clipboard

Copied

THANKS ITS WORK NOW 

 

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 ,
Jan 08, 2022 Jan 08, 2022

Copy link to clipboard

Copied

Ah, I just saw your latest post after my previous reply.

 

Glad it is working for you now.

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