• 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 align values of chart images by flip horizontal?

Engaged ,
May 23, 2023 May 23, 2023

Copy link to clipboard

Copied

I receive about 1000 chart images daily that following images are two sample of my images: 

001.jpgUntitled002.jpg 

Now i want to align values of charts using flip horizontal and use photoshop action or script to apply on 1000 daily images like following: 

Video-2023-05-23-195416.gif 

The left side of the chart bars does not need any changes and photoshop action can divide the images into two parts (left side of chart bars - other sides of chart bars) 

next step of action after dividing images, the values on the right side of the chart bars should be selected with Color Range (dark color) 

 

Now i have problem after above step. I must expand selection of values (that i selected by color range) to only left side and selections must extend to the edge of the left border of the layer. 

After extending the selections to the leftmost point of the layer, i can convert each selection to specific layer and every layer can filp horizontal. 

Finally with above steps photoshop action can align all of my images values. 

 

Does anyone have any ideas to solve my problem? 

Please help me in any way you can. If I don't find a solution to this problem, I will lose my job. My only hope is God and this forum and I hope to find a solution for this problem.

TOPICS
Actions and scripting , Windows

Views

4.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 2 Correct answers

Community Expert , Jun 11, 2023 Jun 11, 2023

edited 2023-06-12 

 

 

// moveNumbersLeftOfBarGraphs
// separate elements in specific graphics, put the bars right and align the numbers on the left;
// 2023, use it at your own risk;
var time1 = Number(timeString());
moveNumbersLeftOfBarGraphs ();
var time2 = Number(timeString());
alert("\nthe script took: "+((time2-time1)/1000)+" seconds\nstart "+time1+"\nend "+time2+"\n\n");
////// move numbers to left of bar graphs //////
function moveNumbersLeftOfBarGraphs () {
if (app.documents.length > 0)
...

Votes

Translate

Translate
Community Expert , Jun 16, 2023 Jun 16, 2023

This should perform at least somewhat faster if you want to give it a try: 

// moveNumbersLeftOfBarGraphs
// separate elements in specific graphics, put the bars right and align the numbers on the left;
// ideally bars and logos should be colorful to make numbers better identifyable;
// 2023, use it at your own risk;
executeAction( stringIDToTypeID( "revert" ), undefined, DialogModes.NO );
var time1 = Number(timeString());
moveNumbersLeftOfBarGraphs ();
var time2 = Number(timeString());
alert("\
...

Votes

Translate

Translate
Adobe
Engaged ,
Jun 08, 2023 Jun 08, 2023

Copy link to clipboard

Copied

My problem is not Magic Wand Tool. I used Magic Wand Tool to show you what is my method. after split all bars to seprate layers and remove main layer (layer 1), I must use color range to select right white areas but after theme i can't use delete key to remove white areas from splited layers (i must select each layer and use delete key). i need a way to remove by one key or click. 
note that i can add splited layers to a group and add mask to group and then remove white areas but after remove i can't disband group for flip splited layers. Maybe I need a script that flip horizontal all layers inside a group without disband group.

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 ,
Jun 08, 2023 Jun 08, 2023

Copy link to clipboard

Copied

I am not sure I understand your approach but I think it might not be efficient. 

Why do you even insist of flipping instead of moving? 

 

You seem have drifted considerably from the original post so please provide a new and meaningful description of the exact task you are trying to automate at current with meaningful screenshots including the pertinent Panels. 

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 ,
Jun 09, 2023 Jun 09, 2023

Copy link to clipboard

Copied

quote

I am not sure I understand your approach but I think it might not be efficient. 

Why do you even insist of flipping instead of moving? 

 

You seem have drifted considerably from the original post so please provide a new and meaningful description of the exact task you are trying to automate at current with meaningful screenshots including the pertinent Panels. 


By @c.pfaffenbichler

see following to understand what i want to do: 
Video-2023-06-09-112508(1)-min.gif 

My problem is after using color range tool. after use color range tool i have to select all the layers one by one and press the delete button. How can I teach step after color range to action? 

Different chart images have different number of layers after separating the components into different layers.

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 ,
Jun 09, 2023 Jun 09, 2023

Copy link to clipboard

Copied

But the result seems to be terrible – the bars are not aligned originally and then you cut off parts of the integrated logos to flip with the text … 

Are you sure you understand what you are doing and that are proceeding with a reasonable approach? 

 

Deleting a Selection in all Layers can easily be done with a Script. 

As in this case all the Layers are pixel layers one need not even filter out Adjustment Layers etc. 

 

// 2023, use at your own risk;
if (app.documents.length > 0) {
    var theLayers = collectLayersNamesIndexAndIdentifier ();
    for (var m = 0; m < theLayers.length; m++) {
        selectLayerByID (theLayers[m][2], false);
        try {activeDocument.selection.clear()}
        catch (e) {}
        }
    };
////// collect layers //////
function collectLayersNamesIndexAndIdentifier () {
// the file;
var myDocument = app.activeDocument;
// get number of layers;
var ref = new ActionReference();
ref.putProperty(stringIDToTypeID('property'), stringIDToTypeID('numberOfLayers'));
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
var applicationDesc = executeActionGet(ref);
var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfLayers"));
// process the layers;
var theLayers = new Array;
for (var m = 0; m <= theNumber; m++) {
try {
var ref = new ActionReference();
ref.putIndex( charIDToTypeID( "Lyr " ), m);
var layerDesc = executeActionGet(ref);
var layerSet = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("layerSection")));
var isBackground = layerDesc.getBoolean(stringIDToTypeID("background"));
// if group collect values;
if (layerSet != "layerSectionEnd" && layerSet != "layerSectionStart" && isBackground != true) {
var theName = layerDesc.getString(stringIDToTypeID('name'));
var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));
var theIndex = layerDesc.getInteger(stringIDToTypeID('itemIndex'));
theLayers.push([theName, theIndex, theID])
};
}
catch (e) {};
};
return theLayers
};
////// based on code by mike hale, via paul riggott //////
function selectLayerByID(id,add){ 
add = undefined ? add = false:add 
var ref = new ActionReference();
    ref.putIdentifier(charIDToTypeID("Lyr "), id);
    var desc = new ActionDescriptor();
    desc.putReference(charIDToTypeID("null"), ref );
        if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) ); 
        desc.putBoolean( charIDToTypeID( "MkVs" ), false ); 
    try{
    executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );
}catch(e){
alert(e.message); 
}
};

 

 

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 ,
Jun 09, 2023 Jun 09, 2023

Copy link to clipboard

Copied

quote

But the result seems to be terrible – the bars are not aligned originally and then you cut off parts of the integrated logos to flip with the text … 

Are you sure you understand what you are doing and that are proceeding with a reasonable approach?

By @c.pfaffenbichler

In the conversation we had a few months ago, we explored different ways but we didn't find a suitable solution - the solution I found will solve about 90% of the problem - the remaining small amount of logos can be removed with Photoshop filters

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 ,
Jun 09, 2023 Jun 09, 2023

Copy link to clipboard

Copied

quote

B

By @c.pfaffenbichler

I use following script for split to layers but this code is slow. are you have improved script for split to layer and more faster? 
 

//  photoshopscripts.wordpress.com

////////////////////////////////////
//       Split to Layers 1.0      //
//       2012, David Jensen       //
//                                //
//         With help from         //
//   pfaffenbichler and xbytor    //
//        at ps-scripts.com       //
////////////////////////////////////

#target photoshop

//Change any of the following 5 values to customize the default options for the script:

var showOptionsDialog = true; //Set to false to disable prompt to user.
var tolerance = 0;            // the largest gap of transparent pixels that will be ignored. Also sets default
var confirmThreshold = 20;    // If the script is going to make a large number of layers, prompt user to confirm that this is OK
var suffix = " - ";           // Add this to the Layer name of new Layers.  Set to "" for no additions.
var addCount = true;          // Add a numeral to the end of each new Layer


///////////////////////////////////////
///////////////////////////////////////
///////////////////////////////////////
///////////////////////////////////////
///////////////////////////////////////
var layerNamePreview=activeDocument.activeLayer.name + suffix;
if (addCount === true){
    layerNamePreview += "1";
}

var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.POINTS;

bounds = activeDocument.activeLayer.bounds
var emptyLayer=false;
if (Number(bounds[0]) == 0 && Number(bounds[1]) == 0 && Number(bounds[2]) == 0 && Number(bounds[3]) == 0) {emptyLayer = true};

try{
    if (activeDocument.activeLayer.kind != undefined && activeDocument.activeLayer.isBackgroundLayer == false && emptyLayer == false){
        activeDocument.suspendHistory("Separate", "main()");
    }else{
        alert( "A supported layer kind is not selected.");
    }
}catch(err){
    alert(err)
}

app.preferences.rulerUnits = originalRulerUnits;

function main() {
        
    var ok=createDialog();
    if (ok===2){
        activeDocument.selection.deselect()
        return false;
    }
    baseLayer=activeDocument.activeLayer;
    activeDocument.quickMaskMode = false;
    activeDocument.selection.deselect()
    var layerName = activeDocument.activeLayer.name
    //if a selection can't be made, stop running the script
  
 
    var idCpTL = charIDToTypeID("CpTL");
    executeAction(idCpTL, undefined, DialogModes.NO);
    
    activeDocument.activeLayer.rasterize(RasterizeType.ENTIRELAYER)
    try{
        var idDlt = charIDToTypeID( "Dlt " );
        var desc120 = new ActionDescriptor();
        var idnull = charIDToTypeID( "null" );
        var ref112 = new ActionReference();
        var idChnl = charIDToTypeID( "Chnl" );
        var idChnl = charIDToTypeID( "Chnl" );
        var idMsk = charIDToTypeID( "Msk " );
        ref112.putEnumerated( idChnl, idChnl, idMsk );
        desc120.putReference( idnull, ref112 );
        var idAply = charIDToTypeID( "Aply" );
        desc120.putBoolean( idAply, true );
        executeAction( idDlt, desc120, DialogModes.NO );
    }catch(e){}
    
    
    
    activeDocument.activeLayer.name = layerName

    baseLayer=activeDocument.activeLayer


    
    makeSelection()

    var idMk = charIDToTypeID("Mk  ");
    var desc642 = new ActionDescriptor();
    var idNw = charIDToTypeID("Nw  ");
    var idDcmn = charIDToTypeID("Dcmn");
    desc642.putClass(idNw, idDcmn);
    var idUsng = charIDToTypeID("Usng");
    var ref535 = new ActionReference();
    var idChnl = charIDToTypeID("Chnl");
    var idOrdn = charIDToTypeID("Ordn");
    var idTrgt = charIDToTypeID("Trgt");
    ref535.putEnumerated(idChnl, idOrdn, idTrgt);
    desc642.putReference(idUsng, ref535);
    executeAction(idMk, desc642, DialogModes.NO);

    newDoc = activeDocument
    // =======================================================
    activeDocument.resizeImage("200%", "200%", undefined, ResampleMethod.NEARESTNEIGHBOR)

    // =======================================================
    var idsetd = charIDToTypeID("setd");
    var desc934 = new ActionDescriptor();
    var idnull = charIDToTypeID("null");
    var ref535 = new ActionReference();
    var idChnl = charIDToTypeID("Chnl");
    var idfsel = charIDToTypeID("fsel");
    ref535.putProperty(idChnl, idfsel);
    desc934.putReference(idnull, ref535);
    var idT = charIDToTypeID("T   ");
    var ref536 = new ActionReference();
    var idChnl = charIDToTypeID("Chnl");
    var idOrdn = charIDToTypeID("Ordn");
    var idTrgt = charIDToTypeID("Trgt");
    ref536.putEnumerated(idChnl, idOrdn, idTrgt);
    desc934.putReference(idT, ref536);
    executeAction(idsetd, desc934, DialogModes.NO);


    var idMk = charIDToTypeID("Mk  ");
    var desc403 = new ActionDescriptor();
    var idnull = charIDToTypeID("null");
    var ref288 = new ActionReference();
    var idPath = charIDToTypeID("Path");
    ref288.putClass(idPath);
    desc403.putReference(idnull, ref288);
    var idFrom = charIDToTypeID("From");
    var ref289 = new ActionReference();
    var idcsel = charIDToTypeID("csel");
    var idfsel = charIDToTypeID("fsel");
    var idfsel = charIDToTypeID("fsel");
    ref289.putProperty(idcsel, idfsel);
    desc403.putReference(idFrom, ref289);
    var idTlrn = charIDToTypeID("Tlrn");
    var idPxl = charIDToTypeID("#Pxl");
    desc403.putUnitDouble(idTlrn, idPxl, 0.500000);
    executeAction(idMk, desc403, DialogModes.NO);
    
    var subPathsLength = activeDocument.pathItems[0].subPathItems.length
    
    if (subPathsLength>confirmThreshold){
        var answer = confirm("Up to "+subPathsLength+ " layers will be created. Would you like to continue?",true)
        if (answer === false){
            newDoc.close(SaveOptions.DONOTSAVECHANGES);
            activeDocument.quickMaskMode = false;
            activeDocument.selection.deselect();
            return 0;
        }
    
    }

    // =======================================================
    activeDocument.resizeImage("50%", "50%", undefined, ResampleMethod.NEARESTNEIGHBOR)

    var pathInfo = collectPathInfoFromDesc(activeDocument, activeDocument.pathItems[activeDocument.pathItems.length - 1])
    
    // =======================================================
    newDoc.close(SaveOptions.DONOTSAVECHANGES)

    // =======================================================
    activeDocument.quickMaskMode = false

    // =======================================================
    //make channel
    // =======================================================
    var idMk = charIDToTypeID("Mk  ");
    var desc6 = new ActionDescriptor();
    var idNw = charIDToTypeID("Nw  ");
    var desc7 = new ActionDescriptor();
    var idNm = charIDToTypeID("Nm  ");
    desc7.putString(idNm, "ContiguityMask");
    var idClrI = charIDToTypeID("ClrI");
    var idMskI = charIDToTypeID("MskI");
    var idMskA = charIDToTypeID("MskA");
    desc7.putEnumerated(idClrI, idMskI, idMskA);
    var idClr = charIDToTypeID("Clr ");
    var desc8 = new ActionDescriptor();
    var idRd = charIDToTypeID("Rd  ");
    desc8.putDouble(idRd, 255.000000);
    var idGrn = charIDToTypeID("Grn ");
    desc8.putDouble(idGrn, 0.000000);
    var idBl = charIDToTypeID("Bl  ");
    desc8.putDouble(idBl, 0.000000);
    var idRGBC = charIDToTypeID("RGBC");
    desc7.putObject(idClr, idRGBC, desc8);
    var idOpct = charIDToTypeID("Opct");
    desc7.putInteger(idOpct, 50);
    var idChnl = charIDToTypeID("Chnl");
    desc6.putObject(idNw, idChnl, desc7);
    var idUsng = charIDToTypeID("Usng");
    var ref5 = new ActionReference();
    var idChnl = charIDToTypeID("Chnl");
    var idfsel = charIDToTypeID("fsel");
    ref5.putProperty(idChnl, idfsel);
    desc6.putReference(idUsng, ref5);
    executeAction(idMk, desc6, DialogModes.NO);


    var layerCount = 1
    for (i = 0; i < subPathsLength; i++) {
        //deselect
        var idsetd = charIDToTypeID("setd");
        var desc279 = new ActionDescriptor();
        var idnull = charIDToTypeID("null");
        var ref137 = new ActionReference();
        var idChnl = charIDToTypeID("Chnl");
        var idfsel = charIDToTypeID("fsel");
        ref137.putProperty(idChnl, idfsel);
        desc279.putReference(idnull, ref137);
        var idT = charIDToTypeID("T   ");
        var idOrdn = charIDToTypeID("Ordn");
        var idNone = charIDToTypeID("None");
        desc279.putEnumerated(idT, idOrdn, idNone);
        executeAction(idsetd, desc279, DialogModes.NO);
        ///select alpha channel
        var idslct = charIDToTypeID("slct");
        var desc315 = new ActionDescriptor();
        var idnull = charIDToTypeID("null");
        var ref175 = new ActionReference();
        var idChnl = charIDToTypeID("Chnl");
        ref175.putName(idChnl, "ContiguityMask");
        desc315.putReference(idnull, ref175);
        executeAction(idslct, desc315, DialogModes.NO);
        //use magic wand
        var idsetd = charIDToTypeID("setd");
        var desc263 = new ActionDescriptor();
        var idnull = charIDToTypeID("null");
        var ref123 = new ActionReference();
        var idChnl = charIDToTypeID("Chnl");
        var idfsel = charIDToTypeID("fsel");
        ref123.putProperty(idChnl, idfsel);
        desc263.putReference(idnull, ref123);
        var idT = charIDToTypeID("T   ");
        var desc264 = new ActionDescriptor();
        var idHrzn = charIDToTypeID("Hrzn");
        var idRlt = charIDToTypeID("#Rlt");
        desc264.putUnitDouble(idHrzn, idRlt, pathInfo[i][0][0]);
        var idVrtc = charIDToTypeID("Vrtc");
        var idRlt = charIDToTypeID("#Rlt");

        desc264.putUnitDouble(idVrtc, idRlt, pathInfo[i][0][1]);
        var idPnt = charIDToTypeID("Pnt ");
        desc263.putObject(idT, idPnt, desc264);
        var idTlrn = charIDToTypeID("Tlrn");
        desc263.putInteger(idTlrn, 1);
        executeAction(idsetd, desc263, DialogModes.NO);

        var idslct = charIDToTypeID("slct");
        var desc346 = new ActionDescriptor();
        var idnull = charIDToTypeID("null");
        var ref205 = new ActionReference();
        var idChnl = charIDToTypeID("Chnl");
        var idChnl = charIDToTypeID("Chnl");
        var idRGB = charIDToTypeID("RGB ");
        ref205.putEnumerated(idChnl, idChnl, idRGB);
        desc346.putReference(idnull, ref205);
        var idMkVs = charIDToTypeID("MkVs");
        desc346.putBoolean(idMkVs, false);
        executeAction(idslct, desc346, DialogModes.NO);




        try {
            // =======================================================
            var idCpTL = charIDToTypeID("CpTL");
            executeAction(idCpTL, undefined, DialogModes.NO);

            try {
                var idrasterizeLayer = stringIDToTypeID("rasterizeLayer");
                var desc924 = new ActionDescriptor();
                var idnull = charIDToTypeID("null");
                var ref721 = new ActionReference();
                var idLyr = charIDToTypeID("Lyr ");
                var idOrdn = charIDToTypeID("Ordn");
                var idTrgt = charIDToTypeID("Trgt");
                ref721.putEnumerated(idLyr, idOrdn, idTrgt);
                desc924.putReference(idnull, ref721);
                var idWhat = charIDToTypeID("What");
                var idrasterizeItem = stringIDToTypeID("rasterizeItem");
                var idvectorMask = stringIDToTypeID("vectorMask");
                desc924.putEnumerated(idWhat, idrasterizeItem, idvectorMask);
                executeAction(idrasterizeLayer, desc924, DialogModes.NO);
            } catch (err) {}

            try {
                var idIntr = charIDToTypeID("Intr");
                var desc864 = new ActionDescriptor();
                var idnull = charIDToTypeID("null");
                var ref658 = new ActionReference();
                var idChnl = charIDToTypeID("Chnl");
                var idOrdn = charIDToTypeID("Ordn");
                var idTrgt = charIDToTypeID("Trgt");
                ref658.putEnumerated(idChnl, idOrdn, idTrgt);
                desc864.putReference(idnull, ref658);
                var idWith = charIDToTypeID("With");
                var ref659 = new ActionReference();
                var idChnl = charIDToTypeID("Chnl");
                var idfsel = charIDToTypeID("fsel");
                ref659.putProperty(idChnl, idfsel);
                desc864.putReference(idWith, ref659);
                executeAction(idIntr, desc864, DialogModes.NO);

                // =======================================================
                var idDlt = charIDToTypeID("Dlt ");
                var desc865 = new ActionDescriptor();
                var idnull = charIDToTypeID("null");
                var ref660 = new ActionReference();
                var idChnl = charIDToTypeID("Chnl");
                var idOrdn = charIDToTypeID("Ordn");
                var idTrgt = charIDToTypeID("Trgt");
                ref660.putEnumerated(idChnl, idOrdn, idTrgt);
                desc865.putReference(idnull, ref660);
                executeAction(idDlt, desc865, DialogModes.NO);

                // =======================================================
                var idMk = charIDToTypeID("Mk  ");
                var desc866 = new ActionDescriptor();
                var idNw = charIDToTypeID("Nw  ");
                var idChnl = charIDToTypeID("Chnl");
                desc866.putClass(idNw, idChnl);
                var idAt = charIDToTypeID("At  ");
                var ref661 = new ActionReference();
                var idChnl = charIDToTypeID("Chnl");
                var idChnl = charIDToTypeID("Chnl");
                var idMsk = charIDToTypeID("Msk ");
                ref661.putEnumerated(idChnl, idChnl, idMsk);
                desc866.putReference(idAt, ref661);
                var idUsng = charIDToTypeID("Usng");
                var idUsrM = charIDToTypeID("UsrM");
                var idRvlS = charIDToTypeID("RvlS");
                desc866.putEnumerated(idUsng, idUsrM, idRvlS);
                executeAction(idMk, desc866, DialogModes.NO);

            } catch (err) {}
            
            var finalSuffix=suffix;
            if (addCount===true)finalSuffix += layerCount;


            activeDocument.activeLayer.name = layerName + finalSuffix;
            layerCount++;
            
            
            activeDocument.activeLayer=baseLayer;
        } catch (e) {}
    }
    var idsetd = charIDToTypeID("setd");
    var desc1045 = new ActionDescriptor();
    var idnull = charIDToTypeID("null");
    var ref578 = new ActionReference();
    var idChnl = charIDToTypeID("Chnl");
    var idfsel = charIDToTypeID("fsel");
    ref578.putProperty(idChnl, idfsel);
    desc1045.putReference(idnull, ref578);
    var idT = charIDToTypeID("T   ");
    var idOrdn = charIDToTypeID("Ordn");
    var idNone = charIDToTypeID("None");
    desc1045.putEnumerated(idT, idOrdn, idNone);
    executeAction(idsetd, desc1045, DialogModes.NO);

    // =======================================================
    var idDlt = charIDToTypeID("Dlt ");
    var desc694 = new ActionDescriptor();
    var idnull = charIDToTypeID("null");
    var ref323 = new ActionReference();
    var idChnl = charIDToTypeID("Chnl");
    ref323.putName(idChnl, "ContiguityMask");
    desc694.putReference(idnull, ref323);
    executeAction(idDlt, desc694, DialogModes.NO);

    
    activeDocument.activeLayer.remove();
    


    var idHd = charIDToTypeID("Hd  ");
    var desc736 = new ActionDescriptor();
    var idnull = charIDToTypeID("null");
    var list22 = new ActionList();
    var ref541 = new ActionReference();
    var idLyr = charIDToTypeID("Lyr ");
    var idOrdn = charIDToTypeID("Ordn");
    var idTrgt = charIDToTypeID("Trgt");
    ref541.putEnumerated(idLyr, idOrdn, idTrgt);
    list22.putReference(ref541);
    desc736.putList(idnull, list22);
    executeAction(idHd, desc736, DialogModes.NO);

}

//   pfaffenbichler and xbytor    //
//        at ps-scripts.com       //
//      created this function     //
function collectPathInfoFromDesc(myDocument, thePath) {
    var myDocument = app.activeDocument;

    // based of functions from xbytor’s stdlib;
    var ref = new ActionReference();
    for (var l = 0; l < myDocument.pathItems.length; l++) {
        var thisPath = myDocument.pathItems[l];
        if (thisPath == thePath && thisPath.name == "Work Path") {
            ref.putProperty(cTID("Path"), cTID("WrPt"));
        };
        if (thisPath == thePath && thisPath.name != "Work Path" && thisPath.kind != PathKind.VECTORMASK) {
            ref.putIndex(cTID("Path"), l + 1);
        };
        if (thisPath == thePath && thisPath.kind == PathKind.VECTORMASK) {
            var idPath = charIDToTypeID("Path");
            var idPath = charIDToTypeID("Path");
            var idvectorMask = stringIDToTypeID("vectorMask");
            ref.putEnumerated(idPath, idPath, idvectorMask);
        };
    };
    var desc = app.executeActionGet(ref);
    var pname = desc.getString(cTID('PthN'));
    // create new array;
    var theArray = new Array;
    var pathComponents = desc.getObjectValue(cTID("PthC")).getList(sTID('pathComponents'));
    // for subpathitems;
    for (var m = 0; m < pathComponents.count; m++) {
        var listKey = pathComponents.getObjectValue(m).getList(sTID("subpathListKey"));
        // for subpathitem’s count;
        for (var n = 0; n < listKey.count; n++) {
            var points = listKey.getObjectValue(n).getList(sTID('points'));
            // get first point;
            var anchorObj = points.getObjectValue(0).getObjectValue(sTID("anchor"));
            var anchor = [anchorObj.getUnitDoubleValue(sTID('horizontal')), anchorObj.getUnitDoubleValue(sTID('vertical'))];
            var thisPoint = [anchor];
            theArray.push(thisPoint);
        };
    };
    // by xbytor, thanks to him;


    function cTID(s) {
        return cTID[s] || cTID[s] = app.charIDToTypeID(s);
    };

    function sTID(s) {
        return sTID[s] || sTID[s] = app.stringIDToTypeID(s);
    };
    // reset;
    return theArray;
};


function makePreviewSelection(){
    makeSelection()    
    app.refresh()
    activeDocument.quickMaskMode = false;
}

function makeSelection(){
    try{
    
        var idsetd = charIDToTypeID("setd");
        var desc922 = new ActionDescriptor();
        var idnull = charIDToTypeID("null");
        var ref529 = new ActionReference();
        var idChnl = charIDToTypeID("Chnl");
        var idfsel = charIDToTypeID("fsel");
        ref529.putProperty(idChnl, idfsel);
        desc922.putReference(idnull, ref529);
        var idT = charIDToTypeID("T   ");
        var ref530 = new ActionReference();
        var idChnl = charIDToTypeID("Chnl");
        var idChnl = charIDToTypeID("Chnl");
        var idTrsp = charIDToTypeID("Trsp");
        ref530.putEnumerated(idChnl, idChnl, idTrsp);
        desc922.putReference(idT, ref530);
        executeAction(idsetd, desc922, DialogModes.NO);

    } catch (err) {
        return false;
    }


    try {
        var idIntr = charIDToTypeID("Intr");
        var desc846 = new ActionDescriptor();
        var idnull = charIDToTypeID("null");
        var ref639 = new ActionReference();
        var idChnl = charIDToTypeID("Chnl");
        var idChnl = charIDToTypeID("Chnl");
        var idMsk = charIDToTypeID("Msk ");
        ref639.putEnumerated(idChnl, idChnl, idMsk);
        desc846.putReference(idnull, ref639);
        var idWith = charIDToTypeID("With");
        var ref640 = new ActionReference();
        var idChnl = charIDToTypeID("Chnl");
        var idfsel = charIDToTypeID("fsel");
        ref640.putProperty(idChnl, idfsel);
        desc846.putReference(idWith, ref640);
        executeAction(idIntr, desc846, DialogModes.NO);


    } catch (err) {}

    try {
        // =======================================================
        var idIntW = charIDToTypeID("IntW");
        var desc787 = new ActionDescriptor();
        var idnull = charIDToTypeID("null");
        var ref572 = new ActionReference();
        var idChnl = charIDToTypeID("Chnl");
        var idfsel = charIDToTypeID("fsel");
        ref572.putProperty(idChnl, idfsel);
        desc787.putReference(idnull, ref572);
        var idT = charIDToTypeID("T   ");
        var ref573 = new ActionReference();
        var idPath = charIDToTypeID("Path");
        var idPath = charIDToTypeID("Path");
        var idvectorMask = stringIDToTypeID("vectorMask");
        ref573.putEnumerated(idPath, idPath, idvectorMask);
        var idLyr = charIDToTypeID("Lyr ");
        var idOrdn = charIDToTypeID("Ordn");
        var idTrgt = charIDToTypeID("Trgt");
        ref573.putEnumerated(idLyr, idOrdn, idTrgt);
        desc787.putReference(idT, ref573);
        var idVrsn = charIDToTypeID("Vrsn");
        desc787.putInteger(idVrsn, 1);
        var idvectorMaskParams = stringIDToTypeID("vectorMaskParams");
        desc787.putBoolean(idvectorMaskParams, true);
        executeAction(idIntW, desc787, DialogModes.NO);
    } catch (err) {}



    if (tolerance >= 2) {

        activeDocument.selection.expand(Math.floor(tolerance / 2))

    }


    activeDocument.quickMaskMode = true;


    var idThrs = charIDToTypeID("Thrs");
    var desc479 = new ActionDescriptor();
    var idLvl = charIDToTypeID("Lvl ");
    desc479.putInteger(idLvl, 1);
    executeAction(idThrs, desc479, DialogModes.NO);



    if (tolerance % 2 == 1) {

        var idMtnB = charIDToTypeID("MtnB");
        var desc213 = new ActionDescriptor();
        var idAngl = charIDToTypeID("Angl");
        desc213.putInteger(idAngl, 0);
        var idDstn = charIDToTypeID("Dstn");
        var idPxl = charIDToTypeID("#Pxl");
        desc213.putUnitDouble(idDstn, idPxl, 1.000000);
        executeAction(idMtnB, desc213, DialogModes.NO);

        // =======================================================
        var idMtnB = charIDToTypeID("MtnB");
        var desc214 = new ActionDescriptor();
        var idAngl = charIDToTypeID("Angl");
        desc214.putInteger(idAngl, 90);
        var idDstn = charIDToTypeID("Dstn");
        var idPxl = charIDToTypeID("#Pxl");
        desc214.putUnitDouble(idDstn, idPxl, 1.000000);
        executeAction(idMtnB, desc214, DialogModes.NO);


        // =======================================================
        var idThrs = charIDToTypeID("Thrs");
        var desc215 = new ActionDescriptor();
        var idLvl = charIDToTypeID("Lvl ");
        desc215.putInteger(idLvl, 1);
        executeAction(idThrs, desc215, DialogModes.NO);
    }
}   

function createDialog(){
        
    var dlg = new Window('dialog', 'Layer Splitter');
    dlg.alignChildren ='left';

    dlg.gap = dlg.add('group')
    dlg.gap.orientation= 'row';
    dlg.gap.txt=dlg.gap.add('statictext', undefined,'Split when gap is larger than');
    dlg.gap.input=dlg.gap.add('edittext', undefined,tolerance);
        dlg.gap.input.preferredSize = [20,20];
    dlg.gap.txt2=dlg.gap.add('statictext', undefined,'pixels');
    dlg.gap.btnPreview= dlg.gap.add('button', undefined,'Preview');
        dlg.gap.btnPreview.preferredSize = [55,20]
    
    dlg.naming = dlg.add('panel',undefined,'Layer Naming') 
    dlg.naming.alignChildren ='left';
        dlg.naming.suffix = dlg.naming.add('group')
        dlg.naming.suffix.orientation= 'row';
        dlg.naming.suffix.txt=dlg.naming.suffix.add('statictext', undefined,'Suffix:');
        dlg.naming.suffix.input=dlg.naming.suffix.add('edittext', undefined,suffix);
            dlg.naming.suffix.input.preferredSize = [60,20];

        dlg.naming.suffix.chkbox = dlg.naming.suffix.add('checkbox', undefined, 'Add Numeral')
            dlg.naming.suffix.chkbox.value=addCount;
        
        dlg.naming.txtPreview = dlg.naming.add('statictext', undefined, layerNamePreview)
            dlg.naming.txtPreview.preferredSize = [200,20];
        
    dlg.btnPnl= dlg.add('group');
    dlg.btnPnl.alignment ='right';
    dlg.btnPnl.okBtn = dlg.btnPnl.add('button', undefined, 'OK', {name:'ok'});
        dlg.btnPnl.okBtn.active=true;
    dlg.btnPnl.cancelBtn = dlg.btnPnl.add('button', undefined, 'Cancel', {name:'cancel'});
      
    dlg.naming.suffix.input.onChanging= function(){
        layerNamePreview=activeDocument.activeLayer.name + dlg.naming.suffix.input.text
        if (dlg.naming.suffix.chkbox.value === true){
            layerNamePreview += "1"
        }
        dlg.naming.txtPreview.text =layerNamePreview
    }
    dlg.naming.suffix.chkbox.onClick = function(){
        layerNamePreview=activeDocument.activeLayer.name + dlg.naming.suffix.input.text
        if (dlg.naming.suffix.chkbox.value === true){
            layerNamePreview += "1"
        }
        dlg.naming.txtPreview.text = layerNamePreview;
    }

    
        
    
    dlg.gap.input.onChanging = function() {
        if (parseInt(dlg.gap.input.text) == 1){
            dlg.gap.txt2.text = 'pixel'
        }else{
            dlg.gap.txt2.text = 'pixels'
        }
        tolerance = parseInt (dlg.gap.input.text)
    }

    dlg.gap.btnPreview.onClick = function() {
        makePreviewSelection()   
    }
    
    x=dlg.show(); 
    
    tolerance = parseInt (dlg.gap.input.text)
    suffix = dlg.naming.suffix.input.text
    addCount=dlg.naming.suffix.chkbox.value
    
    return x;
}

 

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

Copy link to clipboard

Copied

quote

But the result seems to be terrible – the bars are not aligned originally and then you cut off parts of the integrated logos to flip with the text … 

Are you sure you understand what you are doing and that are proceeding with a reasonable approach? 

 

Deleting a Selection in all Layers can easily be done with a Script. 

As in this case all the Layers are pixel layers one need not even filter out Adjustment Layers etc. 

 

 

 

// 2023, use at your own risk;
if (app.documents.length > 0) {
    var theLayers = collectLayersNamesIndexAndIdentifier ();
    for (var m = 0; m < theLayers.length; m++) {
        selectLayerByID (theLayers[m][2], false);
        try {activeDocument.selection.clear()}
        catch (e) {}
        }
    };
////// collect layers //////
function collectLayersNamesIndexAndIdentifier () {
// the file;
var myDocument = app.activeDocument;
// get number of layers;
var ref = new ActionReference();
ref.putProperty(stringIDToTypeID('property'), stringIDToTypeID('numberOfLayers'));
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
var applicationDesc = executeActionGet(ref);
var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfLayers"));
// process the layers;
var theLayers = new Array;
for (var m = 0; m <= theNumber; m++) {
try {
var ref = new ActionReference();
ref.putIndex( charIDToTypeID( "Lyr " ), m);
var layerDesc = executeActionGet(ref);
var layerSet = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("layerSection")));
var isBackground = layerDesc.getBoolean(stringIDToTypeID("background"));
// if group collect values;
if (layerSet != "layerSectionEnd" && layerSet != "layerSectionStart" && isBackground != true) {
var theName = layerDesc.getString(stringIDToTypeID('name'));
var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));
var theIndex = layerDesc.getInteger(stringIDToTypeID('itemIndex'));
theLayers.push([theName, theIndex, theID])
};
}
catch (e) {};
};
return theLayers
};
////// based on code by mike hale, via paul riggott //////
function selectLayerByID(id,add){ 
add = undefined ? add = false:add 
var ref = new ActionReference();
    ref.putIdentifier(charIDToTypeID("Lyr "), id);
    var desc = new ActionDescriptor();
    desc.putReference(charIDToTypeID("null"), ref );
        if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) ); 
        desc.putBoolean( charIDToTypeID( "MkVs" ), false ); 
    try{
    executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );
}catch(e){
alert(e.message); 
}
};

 

 

 

 


By @c.pfaffenbichler

sir can you tell me how to run this your script on only selected layers and not all layers? i mean remove active selection from selected layers only and not all layers. what changes i must apply to this your code? 

in previous post someone tell me i must use following code to run any script on selected layers only but i don't know how to add and modify your script with this: 

 

 

#target photoshop

/* Start Process selected layers - from jazz-y */
var s2t = stringIDToTypeID;
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('targetLayersIDs'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
var lrs = executeActionGet(r).getList(p),
    sel = new ActionReference();

for (var i = 0; i < lrs.count; i++) {
    sel.putIdentifier(s2t('layer'), p = lrs.getReference(i).getIdentifier(s2t('layerID')));
    (r = new ActionReference()).putIdentifier(s2t('layer'), p);
    (d = new ActionDescriptor()).putReference(s2t("target"), r);
    executeAction(s2t('select'), d, DialogModes.NO);
/* End Process selected layers - from jazz-y */

// Your code here:
alert(activeDocument.activeLayer.name);

}

 

 

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 ,
Jun 11, 2023 Jun 11, 2023

Copy link to clipboard

Copied

edited 2023-06-12 

 

 

// moveNumbersLeftOfBarGraphs
// separate elements in specific graphics, put the bars right and align the numbers on the left;
// 2023, use it at your own risk;
var time1 = Number(timeString());
moveNumbersLeftOfBarGraphs ();
var time2 = Number(timeString());
alert("\nthe script took: "+((time2-time1)/1000)+" seconds\nstart "+time1+"\nend "+time2+"\n\n");
////// move numbers to left of bar graphs //////
function moveNumbersLeftOfBarGraphs () {
if (app.documents.length > 0) {
// the number of pixels in percent;
var theScale = 400;
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
app.togglePalettes();
var myDocument = app.activeDocument;
if (myDocument.mode != "DocumentMode.RGB") {myDocument.convertProfile ("sRGB IEC61966-2.1", Intent.RELATIVECOLORIMETRIC, true, true)};
var theLayer = myDocument.activeLayer;
// resize image;
myDocument.resizeImage (undefined, undefined, 72, ResampleMethod.NONE);
myDocument.resizeImage (new UnitValue (theScale, "%"), new UnitValue (theScale, "%"), undefined, ResampleMethod.NEARESTNEIGHBOR);
// create path;
loadChannelAsSelection("red", true, false);
loadChannelAsSelection("grain", true, true);
loadChannelAsSelection("blue", true, true);
myDocument.quickMaskMode = true;
applyThreshold(90);
myDocument.quickMaskMode = false;
var theHorStart = myDocument.selection.bounds[0];
var thePathIndex = makeWorkPath2 (1);
var thePath = collectPathInfoFromDesc2023 (myDocument, thePathIndex[0]);
deselect ();
////////////////////////////////////
//deletePath(thePathIndex[0]);
myDocument.pathItems[0].selected = false;
createBackgroundAndSelectiveColorAdjustmentLayerAndThresholdAdjustmentLayer();
////////////////////////////////////
var lineStartExtremes = getSubPathItemExtremes(thePath[0]);
//var theHorStart = lineStartExtremes[0];
var theRectanglesPath = [[thePath[0]]];
var theNumbersPath = [[]];
// process subpathitems;
for (var m = 1; m < thePath.length; m++) {
var theExtremes = getSubPathItemExtremes(thePath[m]);
// check color;
polygonalLassoToolFromPathArray([thePath[m]], false, false);
var theHisto = histogram ();
// add subpathitem if within the vertical dimensions;
if (theExtremes[1] >= lineStartExtremes[1] && theExtremes[3] <= lineStartExtremes[3]) {
// if right of suspected bar;
if (theExtremes[0] > lineStartExtremes[2]) {
// add neutrals to number;
if (theHisto[0][255] > theHisto[1]*0.5) {
theNumbersPath[theNumbersPath.length-1].push(thePath[m])
// add colorful to bar;
} else {
theRectanglesPath[theRectanglesPath.length - 1].push(thePath[m]);
lineStartExtremes[2] = Math.max(lineStartExtremes[2], theExtremes[2])
};
} else {
theRectanglesPath[theRectanglesPath.length - 1].push(thePath[m])
lineStartExtremes[2] = Math.max(lineStartExtremes[2], theExtremes[2])//?
};
// if further down;
} else {
// new rectangle;
if (theExtremes[1] > lineStartExtremes[3] && theExtremes[3] > lineStartExtremes[3]) {
if (theExtremes[0] <= theHorStart + 8 && theExtremes[0] >= theHorStart - 8) {
theRectanglesPath.push([thePath[m]]);
theNumbersPath.push([])
lineStartExtremes = theExtremes;
}
else {
if (theHisto[0][255] > theHisto[1]*0.5) {
theNumbersPath.push([thePath[m]])
} else {
theRectanglesPath[theRectanglesPath.length - 1].push(thePath[m])
lineStartExtremes[2] = Math.max(lineStartExtremes[2], theExtremes[2])//?
};
};
//    lineStartExtremes = theExtremes;
} else {
}
};
};
////////////////////////////////////
myDocument.layers[0].remove();
myDocument.layers[0].remove();
myDocument.layers[1].remove();
deselect ();
////////////////////////////////////
// create the layers;
var theRectangles = new Array;
var theNumbers = new Array;
// create layers for the rectangles;
for (var n = 0; n < theRectanglesPath.length; n++) {
polygonalLassoToolFromPathArray(theRectanglesPath[n], false, true);
expandSelection[4];
layerViaCopy ("bar "+(n+1));
deselect ();
theRectangles.push(getLayerIdAndBounds ());
myDocument.activeLayer = theLayer;
};
};
// create layers for the numbers;
for (var o = 0; o < theNumbersPath.length; o++) {
polygonalLassoToolFromPathArray(theNumbersPath[o], false, true);
expandSelection[4];
layerViaCopy ("number "+(o+1));
deselect ();
theNumbers.push(getLayerIdAndBounds ());
myDocument.activeLayer = theLayer;
};
theLayer.visible = false;
////////////////////////////////////
// move layers;
var theHorZero = theRectangles[0][2][0];
var theDist = theNumbers[0][2][0] - theRectangles[0][2][2];
var theWidths = theNumbers.sort(sortArrayByIndexedItem);
var theLongestNumber = theWidths[theWidths.length-1][3];
// move layers;
for (var b = 0; b < theNumbers.length; b++) {
moveLayer(theNumbers[b][1], theHorZero-theNumbers[b][2][0]+theLongestNumber-theNumbers[b][3], 0)
};
for (var c = 0; c < theRectangles.length; c++) {
moveLayer(theRectangles[c][1], theLongestNumber+theDist, 0)
};
////////////////////////////////////
// reset;
myDocument.resizeImage (new UnitValue (10000/theScale, "%"), new UnitValue (10000/theScale, "%"), undefined, ResampleMethod.NEARESTNEIGHBOR);
app.preferences.rulerUnits = originalRulerUnits;
app.togglePalettes();
};
////// collect path info from actiondescriptor, indices start at 1, not 0 //////
function collectPathInfoFromDesc2023 (myDocument, thePath) {
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.POINTS;
// based of functions from xbytor’s stdlib;
var idPath = charIDToTypeID( "Path" );
var ref = new ActionReference();
// check if thePath is an index or a dom-path;
if (thePath.constructor == Number) {
ref.putIndex(idPath, thePath)
}
else {
thePath.select();
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID( "Path" ), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
};
// get stuff;
var desc = app.executeActionGet(ref);
var pname = desc.getString(cTID('PthN'));
// create new array;
var theArray = new Array;
var pathComponents = desc.getObjectValue(cTID("PthC")).getList(sTID('pathComponents'));
// for subpathitems;
for (var m = 0; m < pathComponents.count; m++) {
var listKey = pathComponents.getObjectValue(m).getList(sTID("subpathListKey"));
var operation1 = pathComponents.getObjectValue(m).getEnumerationValue(sTID("shapeOperation"));
switch (operation1) {
case 1097098272:
var operation = 1097098272 //cTID('Add ');
break;
case 1398961266:
var operation = 1398961266 //cTID('Sbtr');
break;
case 1231975538:
var operation = 1231975538 //cTID('Intr');
break;
default:
//		case 1102:
var operation = sTID('xor') //ShapeOperation.SHAPEXOR;
break;
};
// for subpathitem’s count;
for (var n = 0; n < listKey.count; n++) {
theArray.push(new Array);
var points = listKey.getObjectValue(n).getList(sTID('points'));
try {var closed = listKey.getObjectValue(n).getBoolean(sTID("closedSubpath"))}
catch (e) {var closed = false};
// for subpathitem’s segment’s number of points;
for (var o = 0; o < points.count; o++) {
var anchorObj = points.getObjectValue(o).getObjectValue(sTID("anchor"));
var anchor = [anchorObj.getUnitDoubleValue(sTID('horizontal')), anchorObj.getUnitDoubleValue(sTID('vertical'))];
var thisPoint = [anchor];
try {
var left = points.getObjectValue(o).getObjectValue(cTID("Fwd "));
var leftDirection = [left.getUnitDoubleValue(sTID('horizontal')), left.getUnitDoubleValue(sTID('vertical'))];
thisPoint.push(leftDirection)
}
catch (e) {
thisPoint.push(anchor)
};
try {
var right = points.getObjectValue(o).getObjectValue(cTID("Bwd "));
var rightDirection = [right.getUnitDoubleValue(sTID('horizontal')), right.getUnitDoubleValue(sTID('vertical'))];
thisPoint.push(rightDirection)
}
catch (e) {
thisPoint.push(anchor)
};
try {
var smoothOr = points.getObjectValue(o).getBoolean(cTID("Smoo"));
thisPoint.push(smoothOr)
}
catch (e) {thisPoint.push(false)};
theArray[theArray.length - 1].push(thisPoint);
};
theArray[theArray.length - 1].push(closed);
theArray[theArray.length - 1].push(operation);
};
};
// by xbytor, thanks to him;
function cTID (s) { return cTID[s] || cTID[s] = app.charIDToTypeID(s); };
function sTID (s) { return sTID[s] || sTID[s] = app.stringIDToTypeID(s); };
// reset;
app.preferences.rulerUnits = originalRulerUnits;
return theArray;
};
////// delete path by id //////
function deletePath (theID) {
var desc32 = new ActionDescriptor();
var ref9 = new ActionReference();
ref9.putIndex ( stringIDToTypeID( "path" ), theID );
desc32.putReference( stringIDToTypeID( "null" ), ref9 );
executeAction( stringIDToTypeID( "delete" ), desc32, DialogModes.NO );
};
////// load path as selection //////
function loadPathAsSelection (theIndex) {
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putProperty( charIDToTypeID( "Chnl" ), charIDToTypeID( "fsel" ) );
desc1.putReference( charIDToTypeID( "null" ), ref1 );
var ref2 = new ActionReference();
ref2.putIndex( charIDToTypeID( "Path" ), theIndex );
desc1.putReference( charIDToTypeID( "T   " ), ref2 );
desc1.putInteger( charIDToTypeID( "Vrsn" ), 1 );
desc1.putBoolean( stringIDToTypeID( "vectorMaskParams" ), true );
executeAction( charIDToTypeID( "setd" ), desc1, DialogModes.NO );
};
////// determine selected path //////
function selectedPath2020 () {
try {
var ref = new ActionReference();
ref.putProperty (stringIDToTypeID("property"), stringIDToTypeID("targetPathIndex")); 
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
var docDesc = executeActionGet(ref);
var theIndex = docDesc.getInteger(stringIDToTypeID("targetPathIndex"))+1;
//
var ref = new ActionReference();
ref.putIndex( charIDToTypeID("Path"), theIndex); 
var pathDesc = executeActionGet(ref);
var theKind = pathDesc.getEnumerationValue(stringIDToTypeID("kind"));
var theName = pathDesc.getString(stringIDToTypeID("pathName"));
//
return [theIndex, theKind, theName];
}
catch (e) {return undefined}
};
////// make work path from selection //////
function makeWorkPath2 (theTolerance) {
var idPath = charIDToTypeID( "Path" );
var idmake = stringIDToTypeID( "make" );
var idFrom = charIDToTypeID( "From" );
var idnull = stringIDToTypeID( "null" );
// =======================================================
var desc5 = new ActionDescriptor();
var ref3 = new ActionReference();
ref3.putClass( idPath );
desc5.putReference( idnull, ref3 );
var ref4 = new ActionReference();
ref4.putProperty( charIDToTypeID( "csel" ), charIDToTypeID( "fsel" ) );
desc5.putReference( idFrom, ref4 );
desc5.putUnitDouble( charIDToTypeID( "Tlrn" ), charIDToTypeID( "#Pxl" ), theTolerance );
executeAction( idmake, desc5, DialogModes.NO );
// =======================================================
var desc7 = new ActionDescriptor();
var ref3 = new ActionReference();
ref3.putClass( idPath );
desc7.putReference( idnull, ref3 );
var idfrom = stringIDToTypeID( "from" );
var ref4 = new ActionReference();
ref4.putProperty( idPath, stringIDToTypeID( "workPath" ) );
desc7.putReference( idFrom, ref4 );
desc7.putString( stringIDToTypeID( "name" ), Math.random() );
executeAction( idmake, desc7, DialogModes.NO );
try {
var ref = new ActionReference();
ref.putProperty (stringIDToTypeID("property"), stringIDToTypeID("targetPathIndex")); 
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
var docDesc = executeActionGet(ref);
var theIndex = docDesc.getInteger(stringIDToTypeID("targetPathIndex"))+1;
return [theIndex/*, theKind, theName*/];
}
catch (e) {return undefined}
};
////// load layer mask //////
function loadChannelAsSelection1(theName, theInvert, theIntersect) {
if (theIntersect == false ||  theIntersect == undefined) {var idinterfaceWhite = charIDToTypeID( "setd" )}
else {var idinterfaceWhite = stringIDToTypeID( "interfaceWhite" )};
//    alert (typeIDToStringID(idinterfaceWhite));
try {
var idchannel = stringIDToTypeID( "channel" );
var desc70 = new ActionDescriptor();
var ref9 = new ActionReference();
ref9.putProperty( idchannel, stringIDToTypeID( "selection" ) );
desc70.putReference( stringIDToTypeID( "null" ), ref9 );
var ref10 = new ActionReference();
ref10.putEnumerated( idchannel, idchannel, stringIDToTypeID( theName ) );
desc70.putReference( stringIDToTypeID( "to" ), ref10 );
desc70.putBoolean(charIDToTypeID("Invr"), theInvert);
executeAction( idinterfaceWhite, desc70, DialogModes.NO );
//    executeAction( stringIDToTypeID( "set" ), desc70, DialogModes.NO );
} catch (_error) {alert (_error)}
};
////// function to get the date //////
function timeString () {
var now = new Date();
return now.getTime()
};
////// 
function deselect () {
var desc5 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putProperty( stringIDToTypeID( "channel" ), stringIDToTypeID( "selection" ) );
desc5.putReference( stringIDToTypeID( "null" ), ref1 );
desc5.putEnumerated( stringIDToTypeID( "to" ), stringIDToTypeID( "ordinal" ), stringIDToTypeID( "none" ) );
executeAction( stringIDToTypeID( "set" ), desc5, DialogModes.NO );
};
////// x //////
function getSubPathItemExtremes (theArray) {
var theX1 = theArray[0][0][0];
var theX2 = theArray[0][0][0];
var theY1 = theArray[0][0][1];
var theY2 = theArray[0][0][1];
for (var m = 1; m < theArray.length - 2; m++) {
var theX1 = Math.min(theX1, theArray[m][0][0]);
var theX2 = Math.max(theX2, theArray[m][0][0]);
var theY1 = Math.min(theY1, theArray[m][0][1]);
var theY2 = Math.max(theY2, theArray[m][0][1]);
var theWidth = theX2 - theX1;
var theHeight = theY2 - theY1;
//alert ("number "+m+"\n"+theValue+"\n"+theWidth+"___"+theHeight)
};
return [theX1, theY1, theX2, theY2, theWidth, theHeight]
};
////// layer via copy //////
function layerViaCopy (theName) {
// layer via copy;
executeAction( charIDToTypeID( "CpTL" ), undefined, DialogModes.NO );
var desc5 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putEnumerated( stringIDToTypeID( "layer" ), stringIDToTypeID( "ordinal" ), stringIDToTypeID( "targetEnum" ) );
desc5.putReference( stringIDToTypeID( "null" ), ref1 );
var desc6 = new ActionDescriptor();
desc6.putString( stringIDToTypeID( "name" ), theName );
desc5.putObject( stringIDToTypeID( "to" ), stringIDToTypeID( "layer" ), desc6 );
executeAction( stringIDToTypeID( "set" ), desc5, DialogModes.NO );
};
////// apply threshold //////
function applyThreshold (theValue) {
var desc232 = new ActionDescriptor();
desc232.putInteger( stringIDToTypeID( "level" ), theValue );
executeAction( stringIDToTypeID( "thresholdClassEvent" ), desc232, DialogModes.NO );
};
////// load channel as selection //////
function loadChannelAsSelection(theName, theInvert, theAdd) {  
try {
var idchannel = stringIDToTypeID( "channel" );
if (theAdd == false || theAdd == undefined) {
var desc70 = new ActionDescriptor();
var ref9 = new ActionReference();
ref9.putProperty( idchannel, stringIDToTypeID( "selection" ) );
desc70.putReference( stringIDToTypeID( "null" ), ref9 );
var ref10 = new ActionReference();
ref10.putEnumerated( idchannel, idchannel, stringIDToTypeID( theName ) );
desc70.putReference( stringIDToTypeID( "to" ), ref10 );
desc70.putBoolean(charIDToTypeID("Invr"), theInvert);
executeAction( stringIDToTypeID( "set" ), desc70, DialogModes.NO );
} else {
var desc221 = new ActionDescriptor();
var ref5 = new ActionReference();
ref5.putEnumerated( idchannel, idchannel, stringIDToTypeID(theName) );
desc221.putReference( stringIDToTypeID( "null" ), ref5 );
desc221.putBoolean(charIDToTypeID("Invr"), theInvert);
var ref6 = new ActionReference();
ref6.putProperty( idchannel, stringIDToTypeID( "selection" ) );
desc221.putReference( stringIDToTypeID( "to" ), ref6 );
executeAction( stringIDToTypeID( "add" ), desc221, DialogModes.NO );
}
} catch (_error) {alert (_error)}
};
////// make a rectangular selection //////
function rectangularSelection (x1, y1, x2, y2, theAdd) {
if (theAdd == false || theAdd == undefined) {var idset = stringIDToTypeID( "set" )}
else {var idset = stringIDToTypeID( "addTo" )};
var idpixelsUnit = stringIDToTypeID( "pixelsUnit" );
var desc16 = new ActionDescriptor();
var ref2 = new ActionReference();
ref2.putProperty( stringIDToTypeID( "channel" ), stringIDToTypeID( "selection" ) );
desc16.putReference( stringIDToTypeID( "null" ), ref2 );
var desc17 = new ActionDescriptor();
desc17.putUnitDouble( stringIDToTypeID( "top" ), idpixelsUnit, y1 );
desc17.putUnitDouble( stringIDToTypeID( "left" ), idpixelsUnit, x1 );
desc17.putUnitDouble( stringIDToTypeID( "bottom" ), idpixelsUnit, y2 );
desc17.putUnitDouble( stringIDToTypeID( "right" ), idpixelsUnit, x2 );
desc16.putObject( stringIDToTypeID( "to" ), stringIDToTypeID( "rectangle" ), desc17 );
if(theAdd == true) desc16.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) );
executeAction( idset, desc16, DialogModes.NO );
};
////// polygonal lasso tool //////
function polygonalLassoTool (theArray, theSubtract, theAdd) {
if (theSubtract == false || theSubtract == undefined) {var idset = stringIDToTypeID( "set" )}
else {var idset = stringIDToTypeID( "subtractFrom" )};
if (theAdd == true) {var idset = stringIDToTypeID( "addTo" )};
var desc15 = new ActionDescriptor();
var ref2 = new ActionReference();
ref2.putProperty( stringIDToTypeID( "channel" ), stringIDToTypeID( "selection" ) );
desc15.putReference( stringIDToTypeID( "null" ), ref2 );
var desc16 = new ActionDescriptor();
var list2 = new ActionList();
for (var m = 0; m < theArray.length; m++) {
var desc17 = new ActionDescriptor();
var idpixelsUnit = stringIDToTypeID( "pixelsUnit" );
desc17.putUnitDouble( stringIDToTypeID( "horizontal" ), idpixelsUnit, theArray[m][0] );
desc17.putUnitDouble( stringIDToTypeID( "vertical" ), idpixelsUnit, theArray[m][1] );
list2.putObject( stringIDToTypeID( "paint" ), desc17 );
};
desc16.putList( stringIDToTypeID( "points" ), list2 );
desc15.putObject( stringIDToTypeID( "to" ), stringIDToTypeID( "polygon" ), desc16 );
var idantiAlias = stringIDToTypeID( "antiAlias" );
desc15.putBoolean( idantiAlias, false );
executeAction( idset, desc15, DialogModes.NO );
};
////// expand selection //////
function expandSelection (theValue) {
var idExpn = charIDToTypeID( "Expn" );
var desc5 = new ActionDescriptor();
var idBy = charIDToTypeID( "By  " );
var idPxl = charIDToTypeID( "#Pxl" );
desc5.putUnitDouble( idBy, idPxl, theValue );
executeAction( idExpn, desc5, DialogModes.NO );
};
////// get active layer’s id //////
function getLayerIdAndBounds () {
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
var layerDesc = executeActionGet(ref);
var theName = layerDesc.getString(stringIDToTypeID('name'));
var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));
var theBounds = layerDesc.getObjectValue(stringIDToTypeID("bounds"));
var theseBounds = [theBounds.getUnitDoubleValue(stringIDToTypeID("left")), theBounds.getUnitDoubleValue(stringIDToTypeID("top")), theBounds.getUnitDoubleValue(stringIDToTypeID("right")), theBounds.getUnitDoubleValue(stringIDToTypeID("bottom"))];
var theWidth = theseBounds[2]-theseBounds[0];
var theHeight = theseBounds[3]-theseBounds[1];
return [theName, theID, theseBounds, theWidth, theHeight]
};
////// move layer on canvas //////
function moveLayer (theID, hor, ver) {
selectLayerByID(theID, false);
var desc77 = new ActionDescriptor();
var ref38 = new ActionReference();
var idlayer = stringIDToTypeID( "layer" );
ref38.putEnumerated( idlayer, stringIDToTypeID( "ordinal" ), stringIDToTypeID( "targetEnum" ));
desc77.putReference( stringIDToTypeID( "null" ), ref38 );
var idto = stringIDToTypeID( "to" );
var desc78 = new ActionDescriptor();
var idpixelsUnit = stringIDToTypeID( "pixelsUnit" );
desc78.putUnitDouble( stringIDToTypeID( "horizontal" ), idpixelsUnit, hor );
desc78.putUnitDouble( stringIDToTypeID( "vertical" ), idpixelsUnit, ver );
desc77.putObject( idto, stringIDToTypeID( "offset" ), desc78 );
executeAction( stringIDToTypeID( "move" ), desc77, DialogModes.NO );
};
////// based on code by mike hale, via paul riggott //////
function selectLayerByID(id,add){ 
add = undefined ? add = false:add 
var ref = new ActionReference();
ref.putIdentifier(charIDToTypeID("Lyr "), id);
var desc = new ActionDescriptor();
desc.putReference(charIDToTypeID("null"), ref );
if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) ); 
desc.putBoolean( charIDToTypeID( "MkVs" ), false ); 
try{
executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );
}catch(e){
alert(e.message); 
}
};
////// sort a double array, thanks to sam, http://www.rhinocerus.net/forum/lang-javascript/ //////
function sortArrayByIndexedItem(a,b) {
var theIndex = 3;
if (a[theIndex]<b[theIndex]) return -1;
if (a[theIndex]>b[theIndex]) return 1;
return 0;
};
//////
function createBackgroundAndSelectiveColorAdjustmentLayerAndThresholdAdjustmentLayer() {
// =======================================================
var desc5 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putClass( stringIDToTypeID( "layer" ) );
desc5.putReference( stringIDToTypeID( "null" ), ref1 );
executeAction( stringIDToTypeID( "make" ), desc5, DialogModes.NO );
// =======================================================
var desc7 = new ActionDescriptor();
var ref2 = new ActionReference();
ref2.putProperty( charIDToTypeID( "Clr " ), charIDToTypeID( "Clrs" ) );
desc7.putReference( charIDToTypeID( "null" ), ref2 );
executeAction( charIDToTypeID( "Rset" ), desc7, DialogModes.NO );
// =======================================================
var desc10 = new ActionDescriptor();
var ref3 = new ActionReference();
ref3.putClass( stringIDToTypeID( "backgroundLayer" ) );
desc10.putReference( stringIDToTypeID( "null" ), ref3 );
var ref4 = new ActionReference();
ref4.putEnumerated( stringIDToTypeID( "layer" ), stringIDToTypeID( "ordinal" ), stringIDToTypeID( "targetEnum" ) );
desc10.putReference( stringIDToTypeID( "using" ), ref4 );
executeAction( stringIDToTypeID( "make" ), desc10, DialogModes.NO );
// =======================================================
var desc7 = new ActionDescriptor();
var ref5 = new ActionReference();
ref5.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Frwr" ) );
desc7.putReference( charIDToTypeID( "null" ), ref5 );
desc7.putBoolean( charIDToTypeID( "MkVs" ), false );
executeAction( charIDToTypeID( "slct" ), desc7, DialogModes.NO );
// =======================================================
var desc19 = new ActionDescriptor();
var ref6 = new ActionReference();
ref6.putClass( stringIDToTypeID( "adjustmentLayer" ) );
desc19.putReference( stringIDToTypeID( "null" ), ref6 );
var desc20 = new ActionDescriptor();
var desc21 = new ActionDescriptor();
desc21.putEnumerated( stringIDToTypeID( "presetKind" ), stringIDToTypeID( "presetKindType" ), stringIDToTypeID( "presetKindDefault" ) );
var idselectiveColor = stringIDToTypeID( "selectiveColor" );
desc20.putObject( stringIDToTypeID( "type" ), idselectiveColor, desc21 );
var idadjustmentLayer = stringIDToTypeID( "adjustmentLayer" );
desc19.putObject( stringIDToTypeID( "using" ), stringIDToTypeID( "adjustmentLayer" ), desc20 );
executeAction( stringIDToTypeID( "make" ), desc19, DialogModes.NO );
// =======================================================
var idcolors = stringIDToTypeID( "colors" );
var idcolorCorrection = stringIDToTypeID( "colorCorrection" );
var desc137 = new ActionDescriptor();
var ref18 = new ActionReference();
ref18.putEnumerated( stringIDToTypeID( "adjustmentLayer" ), stringIDToTypeID( "ordinal" ), stringIDToTypeID( "targetEnum" ) );
desc137.putReference( stringIDToTypeID( "null" ), ref18 );
var desc138 = new ActionDescriptor();
var list12 = new ActionList();
var desc139 = new ActionDescriptor();
desc139.putEnumerated( idcolors, idcolors, stringIDToTypeID( "magenta" ) );
desc139.putUnitDouble( stringIDToTypeID( "black" ), stringIDToTypeID( "percentUnit" ), 100.000000 );
list12.putObject( idcolorCorrection, desc139 );
var desc139 = new ActionDescriptor();
desc139.putEnumerated( idcolors, idcolors, stringIDToTypeID( "reds" ) );
desc139.putUnitDouble( stringIDToTypeID( "black" ), stringIDToTypeID( "percentUnit" ), 100.000000 );
list12.putObject( idcolorCorrection, desc139 );
var desc139 = new ActionDescriptor();
desc139.putEnumerated( idcolors, idcolors, stringIDToTypeID( "yellows" ) );
desc139.putUnitDouble( stringIDToTypeID( "black" ), stringIDToTypeID( "percentUnit" ), 100.000000 );
list12.putObject( idcolorCorrection, desc139 );
var desc139 = new ActionDescriptor();
desc139.putEnumerated( idcolors, idcolors, stringIDToTypeID( "greens" ) );
desc139.putUnitDouble( stringIDToTypeID( "black" ), stringIDToTypeID( "percentUnit" ), 100.000000 );
list12.putObject( idcolorCorrection, desc139 );
var desc139 = new ActionDescriptor();
desc139.putEnumerated( idcolors, idcolors, stringIDToTypeID( "blues" ) );
desc139.putUnitDouble( stringIDToTypeID( "black" ), stringIDToTypeID( "percentUnit" ), 100.000000 );
list12.putObject( idcolorCorrection, desc139 );
var desc139 = new ActionDescriptor();
desc139.putEnumerated( idcolors, idcolors, stringIDToTypeID( "cyans" ) );
desc139.putUnitDouble( stringIDToTypeID( "black" ), stringIDToTypeID( "percentUnit" ), 100.000000 );
list12.putObject( idcolorCorrection, desc139 );
var desc139 = new ActionDescriptor();
desc139.putEnumerated( idcolors, idcolors, stringIDToTypeID( "whites" ) );
desc139.putUnitDouble( stringIDToTypeID( "black" ), stringIDToTypeID( "percentUnit" ), -100.000000 );
list12.putObject( idcolorCorrection, desc139 );
var desc139 = new ActionDescriptor();
desc139.putEnumerated( idcolors, idcolors, stringIDToTypeID( "neutrals" ) );
desc139.putUnitDouble( stringIDToTypeID( "black" ), stringIDToTypeID( "percentUnit" ), -100.000000 );
list12.putObject( idcolorCorrection, desc139 );
var desc139 = new ActionDescriptor();
desc139.putEnumerated( idcolors, idcolors, stringIDToTypeID( "blacks" ) );
desc139.putUnitDouble( stringIDToTypeID( "black" ), stringIDToTypeID( "percentUnit" ), -100.000000 );
list12.putObject( idcolorCorrection, desc139 );
desc138.putList( idcolorCorrection, list12 );
desc138.putEnumerated( stringIDToTypeID( "method" ), stringIDToTypeID( "correctionMethod" ), stringIDToTypeID( "absolute" ) );
var idselectiveColor = stringIDToTypeID( "selectiveColor" );
desc137.putObject( stringIDToTypeID( "to" ), idselectiveColor, desc138 );
executeAction( stringIDToTypeID( "set" ), desc137, DialogModes.NO );
// =======================================================
var desc211 = new ActionDescriptor();
var ref25 = new ActionReference();
ref25.putClass( stringIDToTypeID( "adjustmentLayer" ) );
desc211.putReference( stringIDToTypeID( "null" ), ref25 );
var desc212 = new ActionDescriptor();
var desc213 = new ActionDescriptor();
desc213.putInteger( stringIDToTypeID( "level" ), 220 );
var idthresholdClassEvent = stringIDToTypeID( "thresholdClassEvent" );
desc212.putObject( stringIDToTypeID( "type" ), idthresholdClassEvent, desc213 );
var idadjustmentLayer = stringIDToTypeID( "adjustmentLayer" );
desc211.putObject( stringIDToTypeID( "using" ), idadjustmentLayer, desc212 );
executeAction( stringIDToTypeID( "make" ), desc211, DialogModes.NO );

};
////// get histogram //////
function histogram () {
var ref = new ActionReference();
ref.putProperty (stringIDToTypeID ("property"), stringIDToTypeID ("histogram"));
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var docDesc = executeActionGet(ref);
var list = docDesc.getList(stringIDToTypeID("histogram"));
var theArray = new Array;
var theTotal = 0;
for (var i = 0; i < list.count; i++) {
var d = list.getInteger(i);
theArray.push(d);
theTotal = theTotal+d;
};
return [theArray, theTotal];
};
////// x //////
function polygonalLassoToolFromPathArray (theArray, theSubtract, theAdd) {
for (var a = 0; a < theArray.length; a++) {
var thisOne = theArray[a];
var thisArray = new Array;
for (var k = 0; k < thisOne.length-2; k++){
thisArray.push(thisOne[k][0])
};
polygonalLassoTool(thisArray, theSubtract, theAdd);
};
};

 

 

 

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 ,
Jun 11, 2023 Jun 11, 2023

Copy link to clipboard

Copied

quote

By @c.pfaffenbichler

Untitl5345345345ed.jpg

what is this error? i tried to run your latest reply script on some samples but i get this error

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 ,
Jun 11, 2023 Jun 11, 2023

Copy link to clipboard

Copied

If at this point it is still not obvious to you that you need to provide affected file/s for testing this seems pointless. 

 

I have not tested on all the images you sent but the Script worked for at least one file from the five folders you sent. 

Screenshot 2023-06-12 at 08.07.51.png

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 ,
Jun 12, 2023 Jun 12, 2023

Copy link to clipboard

Copied

quote

If at this point it is still not obvious to you that you need to provide affected file/s for testing this seems pointless.

By @c.pfaffenbichler

idk, this time even i installed latest version of photoshop (24.5) and tried your script and get following error!
Untitl5345435345ed.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 ,
Jun 12, 2023 Jun 12, 2023

Copy link to clipboard

Copied

Your claim is meaningless unless you provide the files on which the problems happen – both the image/s and the jsx-file you are using. 

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 ,
Jun 12, 2023 Jun 12, 2023

Copy link to clipboard

Copied

quote

both the image/s and the jsx-file you are using. 


By @c.pfaffenbichler

i mentioned above jsx file but i can't provide images because i get this error on all of sample image files

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 ,
Jun 12, 2023 Jun 12, 2023

Copy link to clipboard

Copied

What the …? 

The line has be truncated in my last post AGAIN! 

Please correct it manually: 

Screenshot 2023-06-12 at 17.17.39.png

 

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 ,
Jun 12, 2023 Jun 12, 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
Community Expert ,
Jun 12, 2023 Jun 12, 2023

Copy link to clipboard

Copied

Line 68 is damaged, correct it to 

 

if (theExtremes[0] <= theHorStart + 8 && theExtremes[0] >= theHorStart -  {

 

No idea how the error was introduced, copy/pasting code should normally not remove parts … 

 

Edit: And just to be clear: The line was damaged in my post, so it was not your copy/pasting where the error was introduced. 

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 ,
Jun 12, 2023 Jun 12, 2023

Copy link to clipboard

Copied

quote

Line 68 is damaged, correct it to 

 

 

if (theExtremes[0] <= theHorStart + 8 && theExtremes[0] >= theHorStart -  {

 

 

No idea how the error was introduced, copy/pasting code should normally not remove parts … 

 

Edit: And just to be clear: The line was damaged in my post, so it was not your copy/pasting where the error was introduced. 


By @c.pfaffenbichler

i correct it and this time i get following error (on all of image files): 
Untit543535345345led.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 ,
Jun 12, 2023 Jun 12, 2023

Copy link to clipboard

Copied

I sent you a link to a jsx-file that works here. 

 

Way back there used to be regular problems with pasted code, so I’ll post the line again, just to see if the issue persists. 

 

 

if (theExtremes[0] <= theHorStart + 8 && theExtremes[0] >= theHorStart -  {

 

 

 

Edit: test 2

Edit: test 3 

Apparently the code gets truncated when I edit the message.

Screenshot 2023-06-12 at 17.37.56.pngOnce editing commences: Screenshot 2023-06-12 at 17.38.06.png

 

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 ,
Jun 12, 2023 Jun 12, 2023

Copy link to clipboard

Copied

quote

I sent you a link to a jsx-file that works here. 

 

Way back there used to be regular problems with pasted code, so I’ll post the line again, just to see if the issue persists. 

By @c.pfaffenbichler

I downloaded jsx file from your link and renamed it and then tried again but i get following error again!!!! 

Untitl5345435ed.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 ,
Jun 12, 2023 Jun 12, 2023

Copy link to clipboard

Copied

The Script works fine on the file »4 copy.png« you sent previously, so in the absence of a new file (or at least meaningful screenshots) I have nothing more to add. 

Good luck! 

Screenshot 2023-06-12 at 18.09.32.png

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 ,
Jun 12, 2023 Jun 12, 2023

Copy link to clipboard

Copied

quote

The Script works fine on the file »4 copy.png« you sent previously, so in the absence of a new file (or at least meaningful screenshots) I have nothing more to add. 

Good luck! 


By @c.pfaffenbichler

your script everytime stuck at following step and show me that error. 

Untit3425435345led.jpgUntitlerwerwerd.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
Engaged ,
Jun 12, 2023 Jun 12, 2023

Copy link to clipboard

Copied

quote

The Script works fine on the file »4 copy.png« you sent previously, so in the absence of a new file (or at least meaningful screenshots) I have nothing more to add. 

Good luck! 

By @c.pfaffenbichler

can you provide me atn file of steps? maybe this error only appear in script format!

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 ,
Jun 13, 2023 Jun 13, 2023

Copy link to clipboard

Copied

quote

The Script works fine on the file »4 copy.png« you sent previously, so in the absence of a new file (or at least meaningful screenshots) I have nothing more to add. 

Good luck! 

By @c.pfaffenbichler

tnq very much. i modified your script with following code and your script worked successfly: 

////// get histogram //////
function histogram () {

/////////////////
////// select the composite channel as the active channel. the current one can be a mask.
/////////////////
var d = new ActionDescriptor();
var r = new ActionReference();
r.putEnumerated(stringIDToTypeID("channel"), stringIDToTypeID("channel"), stringIDToTypeID("RGB"));
d.putReference(stringIDToTypeID("null"), r);
d.putBoolean(stringIDToTypeID("makeVisible"), false);
executeAction(stringIDToTypeID("select"), d, DialogModes.NO);
/////////////////
/////////////////

var ref = new ActionReference();
ref.putProperty (stringIDToTypeID ("property"), stringIDToTypeID ("histogram"));
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var docDesc = executeActionGet(ref);
var list = docDesc.getList(stringIDToTypeID("histogram"));
var theArray = new Array;
var theTotal = 0;
for (var i = 0; i < list.count; i++) {
var d = list.getInteger(i);
theArray.push(d);
theTotal = theTotal+d;
};
return [theArray, theTotal];
};

  Your script works great, but the speed is very slow. for example in one of images it take 21 second time! 

Untitle45345345345d.jpg 

if i want to run your script on 900 files then it take about 1.5 to 2.5 hour! 

can i run script faster? 

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 ,
Jun 13, 2023 Jun 13, 2023

Copy link to clipboard

Copied

Good detective-work! 

On my computer I turned off the automatic creation of Layer Masks for Adjustment Layers (via the Adjustment Panel’s pop-up-enu) so the Threshold Layer has no Layer Mask and the Composite Channel stays selected – that’s what makes the difference apparently. 

 

On my computer it usually takes about 5 to 6 seconds for the images I tested, but that is not ideal for that volume of images, either. 

There is certainly room for improvement in the Script but at current I don’t have the time to look into it. 

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 ,
Jun 13, 2023 Jun 13, 2023

Copy link to clipboard

Copied

quoteThere is certainly room for improvement in the Script but at current I don’t have the time to look into it. 

By @c.pfaffenbichler

photoshop scripts maybe not good option to batch editing images. 

If there was a solution that would run the created script at a much higher speed in a language like Python programming language, the speed of image editing would increase greatly. 

 

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