abolfazl29032603daba
Engaged
abolfazl29032603daba
Engaged
Activity
‎Sep 23, 2023
09:38 AM
Hello, I think in essence that it could work. I tried it with "Outline robot head" as a starting Prompt. But if you already have a specific idea you maybe look into other Tools like Adobe Illustrator or Adobe Photoshop where you can draw your idea yourself. Or you can combine those Tools to get what you imagine. Hope that helps. By @Henrik Heigl TNQ but it need a description with more details.
... View more
‎Sep 23, 2023
07:02 AM
Hi everyone I want to create very simple logo for my youtube channel that is like very similar to following logo: But I don't want to design it. I want to create it by AI. how can I create this? Can Adobe Firefly design it for me? If Adobe Firefly can design it for me then which service of Adobe Firefly can do it? what I must write for description in that service for create this?
... View more
‎Sep 19, 2023
04:38 AM
There's no exact match in AE, but you could probably re-create it using track mattes, contrast adjustments and generating the repeating woodcut pattern yourself. Mylenium By @Mylenium I'm very begginer in AE. can you send tutorial video for this?
... View more
‎Sep 18, 2023
09:58 PM
1 Upvote
In comica - video filters android app there are some effects like STAMP effect. Now I want to apply this effect on my videos using after effect in pc. How can I do this? Are there any effect like this for after effect? or are there exactly this effect for after effect?
... View more
‎Aug 24, 2023
10:42 AM
1 Upvote
No need answer. I fixed problem by following script: var doc = app.activeDocument;
var guides = doc.guides;
// Initialize the selection with the first guide line
var firstGuide = guides[0];
var startY = firstGuide.coordinate.as("px") - 1;
var endY = guides[1].coordinate.as("px") + 1;
var initialSelection = Array(
[0, startY],
[doc.width, startY],
[doc.width, endY],
[0, endY]
);
doc.selection.select(initialSelection);
// Loop through all other guide lines to accumulate selections
for (var i = 2; i < guides.length; i += 2) {
startY = guides[i].coordinate.as("px") - 1;
endY = guides[i + 1].coordinate.as("px") + 1;
var selectionToAdd = Array(
[0, startY],
[doc.width, startY],
[doc.width, endY],
[0, endY]
);
// Add the new selection to the existing selection with Shift key
doc.selection.select(selectionToAdd, SelectionType.EXTEND);
}
... View more
‎Aug 24, 2023
10:20 AM
With following script I can create some horizontal guide lines with specific horizontal coordinates: var guideCoordinates = [
201,
116,
373,
288,
536,
454,
693,
615,
843,
763,
986,
907,
1124,
1046,
1256,
1178,
1394,
1309,
1503,
1428,
1631,
1545,
1741,
1657,
1837,
1765,
1939,
1867,
2047,
1966
];
var doc = app.activeDocument;
// Loop through the horizontal guide coordinates and create guides
for (var i = 0; i < guideCoordinates.length; i++) {
var y = guideCoordinates[i];
// Create horizontal guide
var horizontalGuide = doc.guides.add(Direction.HORIZONTAL, UnitValue(y, "px"));
} Now I want to select between every two horizontal guide lines by script automatically. for example: Select between 201 and 116 horizontal coordinates add selection of 373 and 288 horizontal coordinates to previous selection add selection of 536 and 454 horizontal coordinates to previous selection add selection of 693 and 615 horizontal coordinates to previous selection ... ... ... please help me to complete this script.
... View more
‎Aug 24, 2023
08:30 AM
T By @c.pfaffenbichler Can I create a dark line in following coordinates (X, Y) without any SubPathInfos? [631, 194],
[494, 123],
[627, 365],
[340, 295],
[637, 529],
[536, 461],
[639, 685],
[490, 622],
[617, 836],
[505, 770],
[646, 979],
[466, 914]
... View more
‎Aug 24, 2023
08:08 AM
You use »doc.pathItems.add()« but you provide only the String for the name. If you consult the reference (»photoshop-javascript-ref-2020.pdf« for example) you will see that the method requires two arguments – the String and the Array of SubPathInfos. By @c.pfaffenbichler please provide edited code that I understand what problem
... View more
‎Aug 24, 2023
07:09 AM
How can I create or draw a dark line in following subpaths coordinates (X, Y) points by photoshop script automatically? High and Low Points Info: Subpath 1: Highest Point: (631, 194) Lowest Point: (494, 123) Subpath 2: Highest Point: (627, 365) Lowest Point: (340, 295) Subpath 3: Highest Point: (637, 529) Lowest Point: (536, 461) Subpath 4: Highest Point: (639, 685) Lowest Point: (490, 622) Subpath 5: Highest Point: (617, 836) Lowest Point: (505, 770) Subpath 6: Highest Point: (646, 979) Lowest Point: (466, 914) The angle of the created lines must be zero or 180 I wrote following script but I get error: var doc = app.activeDocument;
var points = [
[631, 194],
[494, 123],
[627, 365],
[340, 295],
[637, 529],
[536, 461],
[639, 685],
[490, 622],
[617, 836],
[505, 770],
[646, 979],
[466, 914]
];
var lineThickness = 2; // Thickness of the lines
var lineColor = new SolidColor();
lineColor.rgb.red = 0; // Red value of the color
lineColor.rgb.green = 0; // Green value of the color
lineColor.rgb.blue = 0; // Blue value of the color
for (var i = 0; i < points.length; i++) {
var startPoint = points[i];
var endPoint = points[(i + 1) % points.length]; // Circular connectivity
var lineSubPath = new SubPathInfo();
lineSubPath.closed = false;
lineSubPath.operation = ShapeOperation.SHAPEADD;
lineSubPath.entireSubPath = [startPoint, endPoint];
var linePathItem = doc.pathItems.add("Custom Line");
linePathItem.subPathItems.add(lineSubPath);
var lineLayer = doc.activeLayer;
lineLayer.strokePath(ToolType.PENCIL);
lineLayer.strokeWidth = lineThickness;
lineLayer.strokeColor = lineColor;
// Adjust line's angle
lineLayer.rotate(-90); // Rotate the line by 90 degrees to get a zero-degree angle
} I get following error and my script not working!! where is my script problem?
... View more
‎Aug 22, 2023
01:18 AM
I write following script by ChatGPT and it working well but before run this script I must convert selection to a workpath with name of "Path 1" and after that I can run this script: var doc = app.activeDocument;
var workPathIndex = findWorkPathIndex(doc, "Path 1");
if (workPathIndex >= 0) {
var workPath = doc.pathItems[workPathIndex];
markSubpathCenters(workPath);
} else {
alert("Work path 'Path 1' not found.");
}
function findWorkPathIndex(document, workPathName) {
for (var i = 0, len = document.pathItems.length; i < len; i++) {
if (document.pathItems[i].name === workPathName) {
return i;
}
}
return -1;
}
function markSubpathCenters(workPath) {
var subPathCenters = [];
for (var i = 0, len = workPath.subPathItems.length; i < len; i++) {
var subPath = workPath.subPathItems[i];
var center = getSubpathCenter(subPath);
if (center) {
subPathCenters.push(center);
}
}
createMarkers(subPathCenters);
}
function getSubpathCenter(subPath) {
var pathPoints = subPath.pathPoints;
if (pathPoints.length > 0) {
var totalX = 0;
var totalY = 0;
for (var i = 0, len = pathPoints.length; i < len; i++) {
totalX += pathPoints[i].anchor[0];
totalY += pathPoints[i].anchor[1];
}
var centerX = totalX / pathPoints.length;
var centerY = totalY / pathPoints.length;
return [centerX, centerY];
}
return null;
}
function createMarkers(centers) {
var markerLayer = doc.artLayers.add();
markerLayer.kind = LayerKind.TEXT;
var textItem = markerLayer.textItem;
textItem.contents = "+";
textItem.size = 124;
textItem.color.rgb.hexValue = "000000";
textItem.justification = Justification.CENTER;
for (var i = 0, len = centers.length; i < len; i++) {
var center = centers[i];
var x = center[0];
var y = center[1];
var markerCopy = markerLayer.duplicate();
markerCopy.textItem.position = [x, y];
}
}
... View more
‎Aug 21, 2023
09:25 PM
I can do this by custom pattern and random fill with "+" character but it is not accurate:
... View more
‎Aug 21, 2023
08:21 AM
@c.pfaffenbichler @Stephen Marsh @r-bin Can you tell me how can i get info of selected areas by script for this process?
... View more
‎Aug 21, 2023
12:22 AM
Sometimes I have high number of chart images and convert them to following by photoshop action: above images are 3 transparent sample of my edited chart images. Now I want to write a word or special character in the selected areas automatically like following: above screenshot is selected areas. In following I write "#" in front of left side chart names: I must do this automatically by photoshop action or script. Note that number of selected areas in each image maybe different and script or action must write # in all of selected areas. Note that I don't want to split selected areas to multiple layers because I want to edit high number of chart images and it take long time. I attach my 3 sample as gif file in this post for test.
... View more
‎Aug 16, 2023
08:01 AM
1 Upvote
The value in the line expandSelection(12); appears to be too big for this image. By @c.pfaffenbichler Wow you are amazing.
... View more
‎Aug 15, 2023
11:28 AM
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.
... View more
‎Aug 15, 2023
06:37 AM
C By @c.pfaffenbichler Hi, Can you tell me why following photoshop script that you provide to me why not working on attached sample JPG file? https://drive.google.com/file/d/1Ll8auf_e2g4qdYyhPAzPXyb0zwgFS20k/view?usp=sharing Please tell me how you find problem too. for example with which tool you found that image have dirt
... View more
‎Aug 07, 2023
12:40 AM
I want to do something like following transform: I attach here sample JPG file
... View more
‎Aug 07, 2023
12:21 AM
3 Upvotes
I want to transform a selection in my image to very high size but sometimes i get following error: How can i fix this error? How to make bounds of document unlimited?
... View more
‎Jul 26, 2023
03:21 AM
Are there any way to get height of png components without split them to specific layers? For example in attached png file i can split components to specific layers and after that i get all layers height but i don't like to split png components to specific layers. If have any code for this, please provide here.
... View more
‎Jul 24, 2023
07:08 AM
That takes some specific changes and those might not work out on other images. Also there is a dark line on the left edge and the colorful headline could become a problem. By @c.pfaffenbichler If i get different image with different background color next time, can i modify your script by chatGPT for it? If i want to modify your script for it, what i must request from chatGPT? for example i must get color code of background and text color code and provide them to chatGPT and what i must ask from it?
... View more
‎Jul 21, 2023
08:59 PM
T By @c.pfaffenbichler Can you tell me how to increase space that must apply by following script between layers to 2X? (this is your script that shared with me before) By @abolfazl29032603daba @c.pfaffenbichler no need answer sir I modified it by chatGPT // lift discontinuous content from layer onto individual layers and offset them;
// for rgb-images;
// 2023, use it at your own risk;
if (app.documents.length > 0 && app.activeDocument.mode == DocumentMode.RGB && activeDocument.activeLayer.kind == "LayerKind.NORMAL") {
app.activeDocument.suspendHistory("split layers", "main ()");
};
function main () {
myDocument = app.activeDocument;
myDocument.activeChannels = [myDocument.channels[0], myDocument.channels[1], myDocument.channels[2]];
var theOffset = 100;
// load transarency;
// =======================================================
var desc11 = new ActionDescriptor();
var ref6 = new ActionReference();
ref6.putProperty( charIDToTypeID( "Chnl" ), charIDToTypeID( "fsel" ) );
desc11.putReference( charIDToTypeID( "null" ), ref6 );
var ref7 = new ActionReference();
ref7.putEnumerated( charIDToTypeID( "Chnl" ), charIDToTypeID( "Chnl" ), charIDToTypeID( "Trsp" ) );
desc11.putReference( charIDToTypeID( "T " ), ref7 );
executeAction( charIDToTypeID( "setd" ), desc11, DialogModes.NO );
//
var check = true;
// set to pixels;
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
// set to 72ppi;
var originalResolution = app.activeDocument.resolution;
myDocument.resizeImage (undefined, undefined, 72, ResampleMethod.NONE);
var theLayer = myDocument.activeLayer;
// use threshold to heighten non black pixels;
myDocument.quickMaskMode = true;
myDocument.activeLayer.threshold(1);
myDocument.quickMaskMode = false;
// create work path;
makeWorkPath2(1);
var subPathsNumber = myDocument.pathItems[myDocument.pathItems.length-1].subPathItems.length;
// do the operation;
{
var thePathInfo = collectPathInfoFromDesc2012(myDocument, myDocument.pathItems[myDocument.pathItems.length-1]);
var theLayers = new Array;
// create one path for every subpathitem:
for (var m = 0; m < thePathInfo.length; m++) {
var theSubPath = thePathInfo[m];
var aPath = createPath2012 ([theSubPath], m+"_path");
aPath.makeSelection(0, true, SelectionType.REPLACE);
// expand;
myDocument.selection.expand(6);
// layer via copy;
try {
var id14 = charIDToTypeID( "CpTL" );
executeAction( id14, undefined, DialogModes.NO );
myDocument.activeLayer.name = theLayer.name + "_" + (m+1)
}
catch (e) {};
theLayers.push(myDocument.activeLayer);
myDocument.pathItems[myDocument.pathItems.length-1].remove();
myDocument.activeLayer = theLayer;
};
theLayer.visible = false;
};
// offset;
for (var n = 1; n < theLayers.length; n++) {
theLayers[n].translate (0, theOffset*2*n);
};
myDocument.crop([0 ,0 ,myDocument.width, myDocument.height + theOffset *2* (theLayers.length-1)]);
// reset;
app.preferences.rulerUnits = originalRulerUnits;
myDocument.resizeImage (undefined, undefined, originalResolution, ResampleMethod.NONE);
};
////////////////////////////////////
////////////////////////////////////
////////////////////////////////////
////// collect path info from actiondescriptor, smooth added //////
function collectPathInfoFromDesc2012 (myDocument, thePath) {
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.POINTS;
// 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"));
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;
};
////// create a path from collectPathInfoFromDesc2012-array //////
function createPath2012(theArray, thePathsName) {
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.POINTS;
// thanks to xbytor;
cTID = function(s) {return app.charIDToTypeID(s)};
sTID = function(s) {return app.stringIDToTypeID(s)};
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putProperty(cTID('Path'), cTID('WrPt'));
desc1.putReference(sTID('null'), ref1);
var list1 = new ActionList();
for (var m = 0; m < theArray.length; m++) {
var thisSubPath = theArray[m];
var desc2 = new ActionDescriptor();
desc2.putEnumerated(sTID('shapeOperation'), sTID('shapeOperation'), thisSubPath[thisSubPath.length - 1]);
var list2 = new ActionList();
var desc3 = new ActionDescriptor();
desc3.putBoolean(cTID('Clsp'), thisSubPath[thisSubPath.length - 2]);
var list3 = new ActionList();
for (var n = 0; n < thisSubPath.length - 2; n++) {
var thisPoint = thisSubPath[n];
var desc4 = new ActionDescriptor();
var desc5 = new ActionDescriptor();
desc5.putUnitDouble(cTID('Hrzn'), cTID('#Rlt'), thisPoint[0][0]);
desc5.putUnitDouble(cTID('Vrtc'), cTID('#Rlt'), thisPoint[0][1]);
desc4.putObject(cTID('Anch'), cTID('Pnt '), desc5);
var desc6 = new ActionDescriptor();
desc6.putUnitDouble(cTID('Hrzn'), cTID('#Rlt'), thisPoint[1][0]);
desc6.putUnitDouble(cTID('Vrtc'), cTID('#Rlt'), thisPoint[1][1]);
desc4.putObject(cTID('Fwd '), cTID('Pnt '), desc6);
var desc7 = new ActionDescriptor();
desc7.putUnitDouble(cTID('Hrzn'), cTID('#Rlt'), thisPoint[2][0]);
desc7.putUnitDouble(cTID('Vrtc'), cTID('#Rlt'), thisPoint[2][1]);
desc4.putObject(cTID('Bwd '), cTID('Pnt '), desc7);
desc4.putBoolean(cTID('Smoo'), thisPoint[3]);
list3.putObject(cTID('Pthp'), desc4);
};
desc3.putList(cTID('Pts '), list3);
list2.putObject(cTID('Sbpl'), desc3);
desc2.putList(cTID('SbpL'), list2);
list1.putObject(cTID('PaCm'), desc2);
};
desc1.putList(cTID('T '), list1);
executeAction(cTID('setd'), desc1, DialogModes.NO)
if (hasVectorMask() == false) {
app.activeDocument.pathItems[app.activeDocument.pathItems.length - 1].name = thePathsName;
var myPathItem = app.activeDocument.pathItems[app.activeDocument.pathItems.length - 1];
}
else {
app.activeDocument.pathItems[app.activeDocument.pathItems.length - 2].name = thePathsName;
var myPathItem = app.activeDocument.pathItems[app.activeDocument.pathItems.length - 2];
};
app.preferences.rulerUnits = originalRulerUnits;
return myPathItem
};
////// 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}
};
// from »Flatten All Masks.jsx« by jeffrey tranberry;
function hasVectorMask() {
var hasVectorMask = false;
try {
var ref = new ActionReference();
var keyVectorMaskEnabled = app.stringIDToTypeID( 'vectorMask' );
var keyKind = app.charIDToTypeID( 'Knd ' );
ref.putEnumerated( app.charIDToTypeID( 'Path' ), app.charIDToTypeID( 'Ordn' ), keyVectorMaskEnabled );
var desc = executeActionGet( ref );
if ( desc.hasKey( keyKind ) ) {
var kindValue = desc.getEnumerationValue( keyKind );
if (kindValue == keyVectorMaskEnabled) {
hasVectorMask = true;
}
}
}catch(e) {
hasVectorMask = false;
}
return hasVectorMask;
};
... View more
‎Jul 21, 2023
08:05 PM
T By @c.pfaffenbichler Can you tell me how to increase space that must apply by following script between layers to 2X? (this is your script that shared with me before) // lift discontinuous content from layer onto individual layers and offset them;
// for rgb-images;
// 2023, use it at your own risk;
if (app.documents.length > 0 && app.activeDocument.mode == DocumentMode.RGB && activeDocument.activeLayer.kind == "LayerKind.NORMAL") {
app.activeDocument.suspendHistory("split layers", "main ()");
};
function main () {
myDocument = app.activeDocument;
myDocument.activeChannels = [myDocument.channels[0], myDocument.channels[1], myDocument.channels[2]];
var theOffset = 50;
// load transarency;
// =======================================================
var desc11 = new ActionDescriptor();
var ref6 = new ActionReference();
ref6.putProperty( charIDToTypeID( "Chnl" ), charIDToTypeID( "fsel" ) );
desc11.putReference( charIDToTypeID( "null" ), ref6 );
var ref7 = new ActionReference();
ref7.putEnumerated( charIDToTypeID( "Chnl" ), charIDToTypeID( "Chnl" ), charIDToTypeID( "Trsp" ) );
desc11.putReference( charIDToTypeID( "T " ), ref7 );
executeAction( charIDToTypeID( "setd" ), desc11, DialogModes.NO );
//
var check = true;
// set to pixels;
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
// set to 72ppi;
var originalResolution = app.activeDocument.resolution;
myDocument.resizeImage (undefined, undefined, 72, ResampleMethod.NONE);
var theLayer = myDocument.activeLayer;
// use threshold to heighten non black pixels;
myDocument.quickMaskMode = true;
myDocument.activeLayer.threshold(1);
myDocument.quickMaskMode = false;
// create work path;
makeWorkPath2(1);
var subPathsNumber = myDocument.pathItems[myDocument.pathItems.length-1].subPathItems.length;
// do the operation;
{
var thePathInfo = collectPathInfoFromDesc2012(myDocument, myDocument.pathItems[myDocument.pathItems.length-1]);
var theLayers = new Array;
// create one path for every subpathitem:
for (var m = 0; m < thePathInfo.length; m++) {
var theSubPath = thePathInfo[m];
var aPath = createPath2012 ([theSubPath], m+"_path");
aPath.makeSelection(0, true, SelectionType.REPLACE);
// expand;
myDocument.selection.expand(6);
// layer via copy;
try {
var id14 = charIDToTypeID( "CpTL" );
executeAction( id14, undefined, DialogModes.NO );
myDocument.activeLayer.name = theLayer.name + "_" + (m+1)
}
catch (e) {};
theLayers.push(myDocument.activeLayer);
myDocument.pathItems[myDocument.pathItems.length-1].remove();
myDocument.activeLayer = theLayer;
};
theLayer.visible = false;
};
// offset;
for (var n = 1; n < theLayers.length; n++) {
theLayers[n].translate (0, theOffset*n);
};
myDocument.crop([0 ,0 ,myDocument.width, myDocument.height + theOffset * (theLayers.length-1)]);
// reset;
app.preferences.rulerUnits = originalRulerUnits;
myDocument.resizeImage (undefined, undefined, originalResolution, ResampleMethod.NONE);
};
////////////////////////////////////
////////////////////////////////////
////////////////////////////////////
////// collect path info from actiondescriptor, smooth added //////
function collectPathInfoFromDesc2012 (myDocument, thePath) {
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.POINTS;
// 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"));
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;
};
////// create a path from collectPathInfoFromDesc2012-array //////
function createPath2012(theArray, thePathsName) {
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.POINTS;
// thanks to xbytor;
cTID = function(s) {return app.charIDToTypeID(s)};
sTID = function(s) {return app.stringIDToTypeID(s)};
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putProperty(cTID('Path'), cTID('WrPt'));
desc1.putReference(sTID('null'), ref1);
var list1 = new ActionList();
for (var m = 0; m < theArray.length; m++) {
var thisSubPath = theArray[m];
var desc2 = new ActionDescriptor();
desc2.putEnumerated(sTID('shapeOperation'), sTID('shapeOperation'), thisSubPath[thisSubPath.length - 1]);
var list2 = new ActionList();
var desc3 = new ActionDescriptor();
desc3.putBoolean(cTID('Clsp'), thisSubPath[thisSubPath.length - 2]);
var list3 = new ActionList();
for (var n = 0; n < thisSubPath.length - 2; n++) {
var thisPoint = thisSubPath[n];
var desc4 = new ActionDescriptor();
var desc5 = new ActionDescriptor();
desc5.putUnitDouble(cTID('Hrzn'), cTID('#Rlt'), thisPoint[0][0]);
desc5.putUnitDouble(cTID('Vrtc'), cTID('#Rlt'), thisPoint[0][1]);
desc4.putObject(cTID('Anch'), cTID('Pnt '), desc5);
var desc6 = new ActionDescriptor();
desc6.putUnitDouble(cTID('Hrzn'), cTID('#Rlt'), thisPoint[1][0]);
desc6.putUnitDouble(cTID('Vrtc'), cTID('#Rlt'), thisPoint[1][1]);
desc4.putObject(cTID('Fwd '), cTID('Pnt '), desc6);
var desc7 = new ActionDescriptor();
desc7.putUnitDouble(cTID('Hrzn'), cTID('#Rlt'), thisPoint[2][0]);
desc7.putUnitDouble(cTID('Vrtc'), cTID('#Rlt'), thisPoint[2][1]);
desc4.putObject(cTID('Bwd '), cTID('Pnt '), desc7);
desc4.putBoolean(cTID('Smoo'), thisPoint[3]);
list3.putObject(cTID('Pthp'), desc4);
};
desc3.putList(cTID('Pts '), list3);
list2.putObject(cTID('Sbpl'), desc3);
desc2.putList(cTID('SbpL'), list2);
list1.putObject(cTID('PaCm'), desc2);
};
desc1.putList(cTID('T '), list1);
executeAction(cTID('setd'), desc1, DialogModes.NO)
if (hasVectorMask() == false) {
app.activeDocument.pathItems[app.activeDocument.pathItems.length - 1].name = thePathsName;
var myPathItem = app.activeDocument.pathItems[app.activeDocument.pathItems.length - 1];
}
else {
app.activeDocument.pathItems[app.activeDocument.pathItems.length - 2].name = thePathsName;
var myPathItem = app.activeDocument.pathItems[app.activeDocument.pathItems.length - 2];
};
app.preferences.rulerUnits = originalRulerUnits;
return myPathItem
};
////// 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}
};
// from »Flatten All Masks.jsx« by jeffrey tranberry;
function hasVectorMask() {
var hasVectorMask = false;
try {
var ref = new ActionReference();
var keyVectorMaskEnabled = app.stringIDToTypeID( 'vectorMask' );
var keyKind = app.charIDToTypeID( 'Knd ' );
ref.putEnumerated( app.charIDToTypeID( 'Path' ), app.charIDToTypeID( 'Ordn' ), keyVectorMaskEnabled );
var desc = executeActionGet( ref );
if ( desc.hasKey( keyKind ) ) {
var kindValue = desc.getEnumerationValue( keyKind );
if (kindValue == keyVectorMaskEnabled) {
hasVectorMask = true;
}
}
}catch(e) {
hasVectorMask = false;
}
return hasVectorMask;
};
... View more
‎Jul 21, 2023
03:09 AM
That takes some specific changes and those might not work out on other images. Also there is a dark line on the left edge and the colorful headline could become a problem. By @c.pfaffenbichler Therefore, isn't it better to create the script in such a way that in each type of chart image, I first select text on the left side with the color range and then execute the script?
... View more
‎Jul 21, 2023
12:39 AM
Another thing: If you have succeeded in automating the processing of images of so many different properties/appearances you should take some pride in that. Maybe you will be able to improve the performance in the future, give it time. By @c.pfaffenbichler Can you tell me how can i use your script on chart images that have not white background? I mean following script that you provided me before: // 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());
////// 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 );
}; I attach a JPG sample here for test
... View more
‎Jul 20, 2023
11:56 PM
1 Upvote
In unusual cases it close image but action still continue remain steps 😕 That’s what the Action is supposed to do. As @r-bin already indicated you can split the Action and insert a conditional (from the Actions Panel’s flyout menu) or you could move all the steps after the Script into a new Action and trigger that from the Script (if the images matches the expectations). By @c.pfaffenbichler OK, tnq very much i fixed problem of my script with @r-bin and your idea.
... View more
‎Jul 20, 2023
09:32 PM
Try inserting a "If the document is open" condition into the action. By @r-bin Can you tell me how? my following script excute in above step // Check all layers except the latest layer's height
function checkLayersHeight() {
try {
var doc = app.activeDocument;
var layers = doc.layers;
var latestLayer = layers[layers.length - 1];
var latestLayerHeight = latestLayer.bounds[3] - latestLayer.bounds[1];
var highestHeight = 0;
// Find the highest height among the shorter layers
for (var i = 0; i < layers.length - 1; i++) {
var layer = layers[i];
var layerHeight = layer.bounds[3] - layer.bounds[1];
if (layerHeight > highestHeight) {
highestHeight = layerHeight;
}
}
// Compare the difference between the highest height and each of the shorter layers' heights
for (var i = 0; i < layers.length - 1; i++) {
var layer = layers[i];
var layerHeight = layer.bounds[3] - layer.bounds[1];
if (Math.abs(highestHeight - layerHeight) > 5) {
doc.close(SaveOptions.DONOTSAVECHANGES);
return; // Stop further processing for this image
}
}
} catch (e) {
alert("Error occurred: " + e);
}
}
// Call the function to check layers' heights
checkLayersHeight(); In unusual cases it close image but action still continue remain steps 😕
... View more
‎Jul 20, 2023
01:18 PM
I written following script that working good but it have a problem: // Check all layers except the latest layer's height
function checkLayersHeight() {
try {
var doc = app.activeDocument;
var layers = doc.layers;
var latestLayer = layers[layers.length - 1];
var latestLayerHeight = latestLayer.bounds[3] - latestLayer.bounds[1];
var highestHeight = 0;
// Find the highest height among the shorter layers
for (var i = 0; i < layers.length - 1; i++) {
var layer = layers[i];
var layerHeight = layer.bounds[3] - layer.bounds[1];
if (layerHeight > highestHeight) {
highestHeight = layerHeight;
}
}
// Compare the difference between the highest height and each of the shorter layers' heights
for (var i = 0; i < layers.length - 1; i++) {
var layer = layers[i];
var layerHeight = layer.bounds[3] - layer.bounds[1];
if (Math.abs(highestHeight - layerHeight) > 5) {
doc.close(SaveOptions.DONOTSAVECHANGES);
return; // Stop further processing for this image
}
}
} catch (e) {
alert("Error occurred: " + e);
}
}
// Call the function to check layers' heights
checkLayersHeight(); this script can only close defective images and can't reset action on next image. then photoshop continue remain action steps on defective images and show following alerts: how to fix this?
... View more
‎Jul 20, 2023
12:14 PM
@c.pfaffenbichler @r-bin @Stephen Marsh I get following script from chatGPT that get all layers except latest layer height, now i don't know what changes i must apply to it for this post script. idk what i must ask from chatGPT to complete this script. // Save all layers except the latest layer's height to a text file
function saveLayersToTextFile() {
try {
var desktopPath = "~/Desktop/followers";
var textFile = new File(desktopPath + "/layers_height.txt");
var layers = app.activeDocument.layers;
var latestLayer = layers[layers.length - 1];
var textData = "";
for (var i = 0; i < layers.length - 1; i++) {
var layer = layers[i];
var layerName = layer.name;
var layerHeight = layer.bounds[3] - layer.bounds[1];
textData += layerName + ": " + layerHeight + " px\r\n";
}
textFile.open("w");
textFile.write(textData);
textFile.close();
alert("Layers' heights have been saved to: " + textFile.fsName);
} catch (e) {
alert("Error occurred: " + e);
}
}
// Call the function to save layers to a text file
saveLayersToTextFile();
... View more
‎Jul 20, 2023
09:10 AM
I will explain my problem quickly. I batch editing high number of images. some of my images are defective. Healthy images are like following. In fact, if we separate the components of the image into different layers, except for the last layer, all the layers have almost the same height. (40,41,42,43,44 pixel). Defective images are like following. In fact, if we separate the components of the image into different layers, except for the last layer, all the layers have not the same height. (40,41,52,43,44 pixel). If you pay close attention, in the defective image, one of the layers has a height of about 10 pixels more than the others. I can't go through all the thousands of images one by one and remove defective or unequal layer height images. I need a script that check image separated layers heights and if all the layers except the last layer have almost the same height, the action processing continues, otherwise the image is closed and the next image is executed. for example: number of layers 7 - height of layers {60,40,42,43,44,39,40} --> script close image and action must excute next image number of layers 9 - height of layers {41,40,42,43,44,39,40,39,38} --> script does not create an obstacle and the action continues its work. note that script no need to separate layers. script run after action separated layers by another script and only check height of layers except latest layer. script decides whether the action will continue or the image will be closed. In fact, the job of script in this case is to find images with mismatched layers (except latest layer). if have any idea or script please provide here.
... View more
‎Jul 19, 2023
02:39 AM
If you can achieve the result you need for all the different graphics you have to process with an Action then that’s fine. I am not interested in this anymore. By @c.pfaffenbichler Finally I found a method that works on almost all chart images. The method I found is not complicated, but it takes nearly 2.5 hours to excute on 1000 images. If I share the method with you here, can you help speed it up? Or you are still not interested in continuing this topic.
... View more