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

how to convert color range selections to rectangular selections?

Engaged ,
Jun 15, 2023 Jun 15, 2023

I have some chart images that i can select all left side texts by color range tool like following: 

selected left side textsselected left side texts 

Now i want to convert all selections to rectangular selections like following: 

example for converted selectionexample for converted selection 

Are there any script to do this conversion? 

please note that I have manually selected only the first three words in the second screenshot to clearly explain the problem. 

I attached sample image for test.

TOPICS
Actions and scripting
2.4K
Translate
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 15, 2023 Jun 15, 2023

 

edited

// selectTextsLeftOfBarGraphs
// create rectangular selection for texts left of bars;
// 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;
var theScale = 2;
var origi
...
Translate
Community Expert , Jun 15, 2023 Jun 15, 2023

Actually, in my fascination for paths, I overlooked that the Selection to determine the leftmost side of the colorful bars itself has bounds and the first Work Path is not necessary. 

Please try this instead: 

// selectTextsLeftOfBarGraphs
// create rectangular selection for texts left of bars;
// 2023, use it at your own risk;
executeAction( stringIDToTypeID( "revert" ), undefined, DialogModes.NO );
var time1 = Number(timeString());
moveNumbersLeftOfBarGraphs ();
var time2 = Number(timeString()
...
Translate
Adobe
Community Expert ,
Jun 15, 2023 Jun 15, 2023

I'm not aware of a script. However, because there are bars to the right, I'd use them to make the selection. Here's one way to use the bars to make the selection:

  1. Select the Magic Wand tool
  2. Shift + click on each of the bars in the bar chart
  3. Select the Rectangular Marquee tool
  4. Hold the Alt (Windows) or Option (macOS) key and starting from the bottom rectangle subtract from the selection so that all the bars are the width of the Sega bars
  5. Press Q or go to Select > Edit in Quick Mask Mode (the selection becomes white and the non-selected area turns red)
  6. Select the Move tool
  7. Hold Shift to constrain movement horizontally and drag to the left
  8. Drag from the small box on the center right of the bounding box to widen the bars (hit Enter or Return or click the checkmark in the Options bar to accept the widening)
  9. Press Q again or go back to Select > Edit in Quick Mask Mode to toggle off Quick Mask Mode
Translate
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 15, 2023 Jun 15, 2023
quote

because there are bars to the right, I'd use them to make the selection.


By @Myra Ferguson

tnq but we can't use right bars for select because some of chart images have zero (0) values and there are no any bar between left side text and zero values!

Translate
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 15, 2023 Jun 15, 2023

 

edited

// selectTextsLeftOfBarGraphs
// create rectangular selection for texts left of bars;
// 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;
var theScale = 2;
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*100, "%"), new UnitValue (theScale*100, "%"), undefined, ResampleMethod.NEARESTNEIGHBOR);
// create path;
createSelectiveColorAdjustmentLayerAndThresholdAdjustmentLayer();
loadChannelAsSelection("red", true, false);
var thePathIndex = makeWorkPath2 (1);
var thePath = collectPathInfoFromDesc2023 (myDocument, thePathIndex[0]);
// determine leftmost colorful element;
var lineStartLeft = myDocument.width;
for (var m = 0; m < thePath.length; m++) {
    var thisSubPath = thePath[m];
    for (var n = 0; n < thisSubPath.length-2; n++) {
        lineStartLeft = Math.min(lineStartLeft, thisSubPath[n][0][0])
    }
};
deletePath (thePathIndex[0]);
////////////////////////////////////
myDocument.layers[0].remove();
myDocument.layers[0].remove();
deselect ();
////////////////////////////////////
loadChannelAsSelection("red", true, false);
rectangularSelection (0, 0, lineStartLeft-4, myDocument.height, false, true);
myDocument.quickMaskMode = true;
useMagicWand2022 ([1,1]);
expandSelection(6);
invertSelection ();
fillWithBlack ("white");
deselect ();
applyThreshold(90);
myDocument.quickMaskMode = false;
var thePathIndex = makeWorkPath2 (0.5);
var thePath = collectPathInfoFromDesc2023 (myDocument, thePathIndex[0]);
deletePath (thePathIndex[0]);
////////////////////////////////////
var lineStartExtremes = getSubPathItemExtremes(thePath[0]);
var theNamesPath = [lineStartExtremes];
// process subpathitems;
for (var m = 1; m < thePath.length; m++) {
var theExtremes = getSubPathItemExtremes(thePath[m]);
// add subpathitem if within the vertical dimensions;
if (theExtremes[1] >= lineStartExtremes[1] && theExtremes[1] <= lineStartExtremes[3]) {
//    if (theExtremes[1] >= lineStartExtremes[1] && theExtremes[3] <= lineStartExtremes[3]) {
        theNamesPath[theNamesPath.length - 1][0] = Math.min(theNamesPath[theNamesPath.length - 1][0], theExtremes[0]);
    theNamesPath[theNamesPath.length - 1][1] = Math.min(theNamesPath[theNamesPath.length - 1][1], theExtremes[1]);
    theNamesPath[theNamesPath.length - 1][2] = Math.max(theNamesPath[theNamesPath.length - 1][2], theExtremes[2]);
    theNamesPath[theNamesPath.length - 1][3] = Math.max(theNamesPath[theNamesPath.length - 1][3], theExtremes[3]);
} else {
// new rectangle;
if (theExtremes[1] > lineStartExtremes[3] && theExtremes[3] > lineStartExtremes[3]) {
    lineStartExtremes = theExtremes;
    theNamesPath.push(theExtremes)
}
};
};
////////////////////////////////////
myDocument.resizeImage (new UnitValue (100/theScale, "%"), new UnitValue (100/theScale, "%"), undefined, ResampleMethod.NEARESTNEIGHBOR);
//alert (theNamesPath.join("\n\n"));
rectangularSelection (theNamesPath[0][0]/theScale, theNamesPath[0][1]/theScale, theNamesPath[0][2]/theScale, theNamesPath[0][3]/theScale, false, false);
for (var n = 0; n < theNamesPath.length; n++) {
    rectangularSelection (theNamesPath[n][0]/theScale, theNamesPath[n][1]/theScale, theNamesPath[n][2]/theScale, theNamesPath[n][3]/theScale, true, false)
};
////////////////////////////////////
// reset;
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}
};
////// 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]
};
////// 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, theIntersect) {
if (theAdd == false || theAdd == undefined) {var idset = stringIDToTypeID( "set" )}
else {var idset = stringIDToTypeID( "addTo" )};
if (theIntersect == true) {var idset = stringIDToTypeID( "interfaceWhite" );};
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 );
};
//////
function createSelectiveColorAdjustmentLayerAndThresholdAdjustmentLayer() {
// =======================================================
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 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 );

};
////// 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);
    };
};
////// use magic wand tool //////
function useMagicWand2022 (theCoord) {
var idnull = charIDToTypeID( "null" );
var idPxl = charIDToTypeID( "#Pxl" );
// select tool;
    var desc2 = new ActionDescriptor();
        var ref2 = new ActionReference();
        ref2.putClass( stringIDToTypeID( "magicWandTool" ) );
    desc2.putReference( idnull, ref2 );
    desc2.putBoolean( stringIDToTypeID( "dontRecord" ), true );
    desc2.putBoolean( stringIDToTypeID( "forceNotify" ), true );
executeAction( charIDToTypeID( "slct" ), desc2, DialogModes.NO );
// apply tool;
    var desc2 = new ActionDescriptor();
        var ref2 = new ActionReference();
        ref2.putProperty( charIDToTypeID( "Chnl" ), charIDToTypeID( "fsel" ) );
    desc2.putReference( idnull, ref2 );
        var desc3 = new ActionDescriptor();
        desc3.putUnitDouble( charIDToTypeID( "Hrzn" ), idPxl, theCoord[0] );
        desc3.putUnitDouble( charIDToTypeID( "Vrtc" ), idPxl, theCoord[1] );
    desc2.putObject( charIDToTypeID( "T   " ), charIDToTypeID( "Pnt " ), desc3 );
    desc2.putInteger( charIDToTypeID( "Tlrn" ), 30 );
    desc2.putBoolean( charIDToTypeID( "AntA" ), true );
    desc2.putBoolean( stringIDToTypeID("merged"), true);
executeAction( charIDToTypeID( "setd" ), desc2, DialogModes.NO );
};
////// fill black //////
function fillWithBlack (theColor) {
try {
var desc20 = new ActionDescriptor();
desc20.putEnumerated( stringIDToTypeID( "using" ), stringIDToTypeID( "fillContents" ), stringIDToTypeID( theColor ) );
desc20.putUnitDouble( stringIDToTypeID( "opacity" ), stringIDToTypeID( "percentUnit" ), 100.000000 );
desc20.putEnumerated( stringIDToTypeID( "mode" ), stringIDToTypeID( "blendMode" ), stringIDToTypeID( "normal" ) );
executeAction( stringIDToTypeID( "fill" ), desc20, DialogModes.NO );
} catch (e) {}
};
////// invert selection //////
function invertSelection () {
// =======================================================
executeAction( charIDToTypeID( "Invs" ), undefined, DialogModes.NO );
};

 

Translate
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 15, 2023 Jun 15, 2023

I forgot to delete the line 

executeAction( stringIDToTypeID( "revert" ), undefined, DialogModes.NO );

that I use for testing. 

Translate
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 15, 2023 Jun 15, 2023
quote

I forgot to delete the line 

executeAction( stringIDToTypeID( "revert" ), undefined, DialogModes.NO );

that I use for testing. 


By @c.pfaffenbichler

wowwww - wonderful 

tnq very much

Translate
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 15, 2023 Jun 15, 2023

Actually, in my fascination for paths, I overlooked that the Selection to determine the leftmost side of the colorful bars itself has bounds and the first Work Path is not necessary. 

Please try this instead: 

// selectTextsLeftOfBarGraphs
// create rectangular selection for texts left of bars;
// 2023, use it at your own risk;
executeAction( stringIDToTypeID( "revert" ), undefined, DialogModes.NO );
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;
var theScale = 2;
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*100, "%"), new UnitValue (theScale*100, "%"), undefined, ResampleMethod.NEARESTNEIGHBOR);
// create path;
createSelectiveColorAdjustmentLayerAndThresholdAdjustmentLayer();
loadChannelAsSelection("red", true, false);
var lineStartLeft = myDocument.selection.bounds[0];
deselect();
////////////////////////////////////
myDocument.layers[0].remove();
myDocument.layers[0].remove();
deselect ();
////////////////////////////////////
loadChannelAsSelection("red", true, false);
rectangularSelection (0, 0, lineStartLeft-4, myDocument.height, false, true);
myDocument.quickMaskMode = true;
useMagicWand2022 ([1,1]);
expandSelection(12);
invertSelection ();
fillWithBlack ("white");
deselect ();
applyThreshold(90);
myDocument.quickMaskMode = false;
var thePathIndex = makeWorkPath2 (0.5);
var thePath = collectPathInfoFromDesc2023 (myDocument, thePathIndex[0]);
deletePath (thePathIndex[0]);
////////////////////////////////////
var lineStartExtremes = getSubPathItemExtremes(thePath[0]);
var theNamesPath = [lineStartExtremes];
// process subpathitems;
for (var m = 1; m < thePath.length; m++) {
var theExtremes = getSubPathItemExtremes(thePath[m]);
// add subpathitem if within the vertical dimensions;
if (theExtremes[1] >= lineStartExtremes[1] && theExtremes[1] <= lineStartExtremes[3]) {
//    if (theExtremes[1] >= lineStartExtremes[1] && theExtremes[3] <= lineStartExtremes[3]) {
        theNamesPath[theNamesPath.length - 1][0] = Math.min(theNamesPath[theNamesPath.length - 1][0], theExtremes[0]);
    theNamesPath[theNamesPath.length - 1][1] = Math.min(theNamesPath[theNamesPath.length - 1][1], theExtremes[1]);
    theNamesPath[theNamesPath.length - 1][2] = Math.max(theNamesPath[theNamesPath.length - 1][2], theExtremes[2]);
    theNamesPath[theNamesPath.length - 1][3] = Math.max(theNamesPath[theNamesPath.length - 1][3], theExtremes[3]);
} else {
// new rectangle;
if (theExtremes[1] > lineStartExtremes[3] && theExtremes[3] > lineStartExtremes[3]) {
    lineStartExtremes = theExtremes;
    theNamesPath.push(theExtremes)
}
};
};
////////////////////////////////////
myDocument.resizeImage (new UnitValue (100/theScale, "%"), new UnitValue (100/theScale, "%"), undefined, ResampleMethod.NEARESTNEIGHBOR);
//alert (theNamesPath.join("\n\n"));
rectangularSelection (theNamesPath[0][0]/theScale, theNamesPath[0][1]/theScale, theNamesPath[0][2]/theScale, theNamesPath[0][3]/theScale, false, false);
for (var n = 0; n < theNamesPath.length; n++) {
    rectangularSelection (theNamesPath[n][0]/theScale, theNamesPath[n][1]/theScale, theNamesPath[n][2]/theScale, theNamesPath[n][3]/theScale, true, false)
};
////////////////////////////////////
// reset;
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}
};
////// 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]
};
////// 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, theIntersect) {
if (theAdd == false || theAdd == undefined) {var idset = stringIDToTypeID( "set" )}
else {var idset = stringIDToTypeID( "addTo" )};
if (theIntersect == true) {var idset = stringIDToTypeID( "interfaceWhite" );};
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 );
};
//////
function createSelectiveColorAdjustmentLayerAndThresholdAdjustmentLayer() {
// =======================================================
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 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 );

};
////// 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);
    };
};
////// use magic wand tool //////
function useMagicWand2022 (theCoord) {
var idnull = charIDToTypeID( "null" );
var idPxl = charIDToTypeID( "#Pxl" );
// select tool;
    var desc2 = new ActionDescriptor();
        var ref2 = new ActionReference();
        ref2.putClass( stringIDToTypeID( "magicWandTool" ) );
    desc2.putReference( idnull, ref2 );
    desc2.putBoolean( stringIDToTypeID( "dontRecord" ), true );
    desc2.putBoolean( stringIDToTypeID( "forceNotify" ), true );
executeAction( charIDToTypeID( "slct" ), desc2, DialogModes.NO );
// apply tool;
    var desc2 = new ActionDescriptor();
        var ref2 = new ActionReference();
        ref2.putProperty( charIDToTypeID( "Chnl" ), charIDToTypeID( "fsel" ) );
    desc2.putReference( idnull, ref2 );
        var desc3 = new ActionDescriptor();
        desc3.putUnitDouble( charIDToTypeID( "Hrzn" ), idPxl, theCoord[0] );
        desc3.putUnitDouble( charIDToTypeID( "Vrtc" ), idPxl, theCoord[1] );
    desc2.putObject( charIDToTypeID( "T   " ), charIDToTypeID( "Pnt " ), desc3 );
    desc2.putInteger( charIDToTypeID( "Tlrn" ), 30 );
    desc2.putBoolean( charIDToTypeID( "AntA" ), true );
    desc2.putBoolean( stringIDToTypeID("merged"), true);
executeAction( charIDToTypeID( "setd" ), desc2, DialogModes.NO );
};
////// fill black //////
function fillWithBlack (theColor) {
try {
var desc20 = new ActionDescriptor();
desc20.putEnumerated( stringIDToTypeID( "using" ), stringIDToTypeID( "fillContents" ), stringIDToTypeID( theColor ) );
desc20.putUnitDouble( stringIDToTypeID( "opacity" ), stringIDToTypeID( "percentUnit" ), 100.000000 );
desc20.putEnumerated( stringIDToTypeID( "mode" ), stringIDToTypeID( "blendMode" ), stringIDToTypeID( "normal" ) );
executeAction( stringIDToTypeID( "fill" ), desc20, DialogModes.NO );
} catch (e) {}
};
////// invert selection //////
function invertSelection () {
// =======================================================
executeAction( charIDToTypeID( "Invs" ), undefined, DialogModes.NO );
};
Translate
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 16, 2023 Jun 16, 2023

yes, it's optimized from 8 second to about 5 second

Translate
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 23, 2023 Jun 23, 2023
quote

Please try this instead: 


By @c.pfaffenbichler

your script is very good but there is one problem. In some chart images not working. for example in attached image. I don't know why. 

Translate
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 24, 2023 Jun 24, 2023

I think it’s the colorful background. 

With this version of the image with a sloppiöy neutralized and lightened background it seems to work. 

Screenshot 2023-06-24 at 12.47.55.png

Translate
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 24, 2023 Jun 24, 2023

tnq - worked for me

Translate
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 05, 2023 Jul 05, 2023
quote

I think it’s the colorful background. 

With this version of the image with a sloppiöy neutralized and lightened background it seems to work. 


By @c.pfaffenbichler

can you check attached JPG file and tell me why script not working on this sample? 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 05, 2023 Jul 05, 2023

There seems to be too much »dirt« (see around line 25) to get the left side of the bars. 

Screenshot 2023-07-06 at 08.54.24.png

Translate
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 ,
Aug 15, 2023 Aug 15, 2023
quote

T

By @c.pfaffenbichler

In attached image i check and not found any dirt but i don't know why script not working and where is problem. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 16, 2023 Aug 16, 2023

The value in the line 

expandSelection(12);

appears to be too big for this image. 

Translate
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 ,
Aug 16, 2023 Aug 16, 2023
LATEST
quote

The value in the line 

 

expandSelection(12);

 

appears to be too big for this image. 


By @c.pfaffenbichler

Wow you are amazing.

Translate
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