If the issue is relevant to your workflow it may well not be very interesting but maybe you should still start a new thread and someone else might have time to chime in.
By @c.pfaffenbichler
ok - i will create a new conversation for it. tnq very much
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("\nthe script took: "+((time2-time1)/1000)+" seconds\nstart "+time1+"\nend "+time2+"\n\n");
////// move numbers to left of bar graphs //////
function moveNumbersLeftOfBarGraphs () {
if (activeDocument.layers.length > 1 || activeDocument.layers[0].isBackgroundLayer == true) {};
if (app.documents.length > 0) {
// the number of pixels in percent;
var theScale = 200;
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;
useMagicWand2022 ([1,1]);
expandSelection(2);
invertSelection ();
fillWithBlack ("white");
deselect ();
// resize;
applyThreshold(90);
myDocument.resizeImage (new UnitValue (theScale, "%"), new UnitValue (theScale, "%"), undefined, ResampleMethod.NEARESTNEIGHBOR);
myDocument.quickMaskMode = false;
var theHorStart = myDocument.selection.bounds[0];
var thePathIndex = makeWorkPath2 (0.5);
var thePath = collectPathInfoFromDesc2023 (myDocument, thePathIndex[0]);
////////////////////////////////////
myDocument.pathItems[0].deselect();
createBackgroundAndSelectiveColorAdjustmentLayerAndThresholdAdjustmentLayer();
////////////////////////////////////
var lineStartExtremes = getSubPathItemExtremes(thePath[0]);
var theRectanglesPath = [[thePath[0]]];
var theNumbersPath = [[]];
// 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[3] <= lineStartExtremes[3]) {
// if right of suspected bar;
if (theExtremes[0] > lineStartExtremes[2]) {
polygonalLassoToolFromPathArray([thePath[m]], false, false);
var theHisto = histogram ();
// 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 - 😎 {
theRectanglesPath.push([thePath[m]]);
theNumbersPath.push([])
lineStartExtremes = theExtremes;
}
else {
polygonalLassoToolFromPathArray([thePath[m]], false, false);
var theHisto = histogram ();
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(2);
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(2);
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 () {
try {
var desc4 = new ActionDescriptor();
var ref1 = new ActionReference();
var idchannel = stringIDToTypeID( "channel" );
ref1.putEnumerated( idchannel, idchannel, stringIDToTypeID( "RGB" ) );
desc4.putReference( stringIDToTypeID( "null" ), ref1 );
executeAction( stringIDToTypeID( "select" ), desc4, DialogModes.NO );
} catch (e) {};
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);
};
};
////// 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 );
};