Copy link to clipboard
Copied
I created some javascript which worked perfectly on previous versions of PS from 2018 to 2020. After update on version 2021 or 2022 my script suddenly slow down. For example before update when i run this code i just see final result but after update i wait for every step of this script. Is it possible to accelerate this script?
var startRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.CM;
var box = new Window('dialog', "INFO");
var a = ["Emp1", "Emp2", "Emp3"];
for (var i = 0; i < a.length; i += 1) {
a["_"+a[i]] = i;
}
var c = ["001", "002", "003", "004","005", "006", "007","008", "009", "010"];
for (var i = 0; i < c.length; i += 1) {
c["_"+c[i]] = i;
}
var d = ["Digital", "Offset", "Flexo"];
for (var i = 0; i < c.length; i += 1) {
d["_"+d[i]] = i;
}
var e = ["RGB", "CMYK", "Multichannel"];
for (var i = 0; i < e.length; i += 1) {
e["_"+e[i]] = i;
}
box.group = box.add('group', undefined );
box.group.orientation='row';
box.group.alignment = 'right';
box.group.text1 = box.group.add('statictext', undefined, "Retoucher");
box.group = box.group.add("dropdownlist", [25,40,160,60], a);
box.group1 = box.add('group', undefined );
box.group1.orientation='row';
box.group1.alignment = 'right';
box.group1.text1 = box.group1.add('statictext', undefined, "Iteration");
box.group1 = box.group1.add("dropdownlist", [25,40,160,60], c);
box.group7 = box.add('group', undefined );
box.group7.orientation='row';
box.group7.alignment = 'right';
box.group7.text1 = box.group7.add('statictext', undefined, "Print method");
box.group7 = box.group7.add("dropdownlist", [25,40,160,60], d);
box.group2 = box.add('group', undefined );
box.group2.orientation='row';
box.group2.alignment = 'right';
box.group2.text1 = box.group2.add('statictext', undefined, "AW Mode");
box.group2 = box.group2.add("dropdownlist", [25,40,160,60], e);
box.group3 = box.add('group', undefined );
box.group3.orientation='row';
box.group3.alignment = 'right';
box.group3.text1 = box.group3.add('statictext', undefined, "Blur filter");
box.group3 = box.group3.add("checkbox", undefined, "Yes");
box.group5 = box.add('group', undefined );
box.group5.orientation='row';
box.group5.alignment = 'right';
box.group5.text1 = box.group5.add('statictext', undefined, "Comments");
box.group5 = box.group5.add('edittext', [25,40,160,160],"",{multiline:true, scrollable:false});
box.group8 = box.add('group', undefined );
box.group8.orientation='row';
box.group8.alignment = 'right';
box.group8.text1 = box.group8.add('statictext', undefined, "Duplicate info");
box.group8 = box.group8.add("checkbox", undefined, "Yes");
var btnGroup = box.add ("group");
btnGroup.orientation = "row";
var btnOk = btnGroup.add("button", undefined, "OK");
var btnCancel = btnGroup.add("button", undefined, "Cancel");
box.center();
btnOk.onClick = function() {
box.close(1);
};
btnCancel.onClick = function() {
box.close(0);
};
if (box.show() === 1) {
app.activeDocument.suspendHistory('INFO','main()');
}
function main(){
var GroupInfo = app.activeDocument.layerSets.add();
if(box.group2.selection){
var it = box.group1.selection.text;
GroupInfo.name = "INFO _" + it;}
else {
GroupInfo.name = "INFO";}
var infobg = app.activeDocument.artLayers.add();
infobg.name = "BG";
var col = new SolidColor();
col.cmyk.cyan = 0;
col.cmyk.magenta = 0;
col.cmyk.yellow = 0;
col.cmyk.black = 0;
var str = new SolidColor();
str.cmyk.cyan = 100;
str.cmyk.magenta = 30;
str.cmyk.yellow = 0;
str.cmyk.black = 0;
var mydocuments = app.activeDocument;
app.preferences.rulerUnits = Units.CM;
var mycm = Number(mydocuments.width);
app.preferences.rulerUnits = Units.PIXELS;
var mypix = Number(mydocuments.width);
mydocuments.selection.select([[0,0],[0,5.5*mypix/mycm],[5.5*mypix/mycm,5.5*mypix/mycm],[5.5*mypix/mycm,0]]);
app.preferences.rulerUnits = Units.CM;
app.activeDocument.selection.fill(col);
app.activeDocument.selection.stroke (str,12,StrokeLocation.INSIDE, ColorBlendMode.NORMAL, 100, false);
activeDocument.selection.deselect();
infobg.move(GroupInfo,ElementPlacement.INSIDE);
if(box.group5.text){
var comments = app.activeDocument.artLayers.add();
comments.kind = LayerKind.TEXT;
comments.textItem.contents = "Comments: \r" + box.group5.text.replace(/\n/g, "\r");
comments.textItem.font = "Helvetica";
comments.textItem.justification = Justification.LEFT;
comments.textItem.position = [0.5, 2.7];
comments.textItem.size = 10;
comments.move(GroupInfo,ElementPlacement.INSIDE)
}
else {
var comments = app.activeDocument.artLayers.add();
comments.kind = LayerKind.TEXT;
comments.textItem.contents = "Comments: /";
comments.textItem.font = "Helvetica";
comments.textItem.justification = Justification.LEFT;
comments.textItem.position = [0.5, 2.7];
comments.textItem.size = 10;
comments.move(GroupInfo,ElementPlacement.INSIDE)
}
if(box.group3.value){
var blurfilter = app.activeDocument.artLayers.add();
blurfilter.kind = LayerKind.TEXT;
blurfilter.textItem.contents = "Blur filter: Yes";
blurfilter.textItem.font = "Helvetica";
blurfilter.textItem.justification = Justification.LEFT;
blurfilter.textItem.position = [0.5, 2.2];
blurfilter.textItem.size = 10;
blurfilter.move(GroupInfo,ElementPlacement.INSIDE)
}
else {
var blurfilter = app.activeDocument.artLayers.add();
blurfilter.kind = LayerKind.TEXT;
blurfilter.textItem.contents = "Blur filter: /";
blurfilter.textItem.font = "Helvetica";
blurfilter.textItem.justification = Justification.LEFT;
blurfilter.textItem.position = [0.5, 2.2];
blurfilter.textItem.size = 10;
blurfilter.move(GroupInfo,ElementPlacement.INSIDE)
}
if(box.group2.selection){
var mode = box.group2.selection.text;
var bmode = app.activeDocument.artLayers.add();
bmode.kind = LayerKind.TEXT;
bmode.textItem.contents = "Trap: " + mode;
bmode.textItem.font = "Helvetica";
bmode.textItem.justification = Justification.LEFT;
bmode.textItem.position = [0.5, 1.7];
bmode.textItem.size = 10;
bmode.move(GroupInfo,ElementPlacement.INSIDE)
}
else {
var bmode = app.activeDocument.artLayers.add();
bmode.kind = LayerKind.TEXT;
bmode.textItem.contents = "Trap: /";
bmode.textItem.font = "Helvetica";
bmode.textItem.justification = Justification.LEFT;
bmode.textItem.position = [0.5, 1.7];
bmode.textItem.size = 10;
bmode.move(GroupInfo,ElementPlacement.INSIDE)
}
if(box.group7.selection){
var pmethod = box.group7.selection.text;
var pm = app.activeDocument.artLayers.add();
pm.kind = LayerKind.TEXT;
pm.textItem.contents = "Method: " + pmethod;
pm.textItem.font = "Helvetica";
pm.textItem.justification = Justification.LEFT;
pm.textItem.position = [0.5, 1.2];
pm.textItem.size = 10;
pm.move(GroupInfo,ElementPlacement.INSIDE)
}
else {
var pm = app.activeDocument.artLayers.add();
pm.kind = LayerKind.TEXT;
pm.textItem.contents = "Method: /";
pm.textItem.font = "Helvetica";
pm.textItem.justification = Justification.LEFT;
pm.textItem.position = [0.5, 1.2];
pm.textItem.size = 10;
pm.move(GroupInfo,ElementPlacement.INSIDE)
}
if(box.group.selection){
var ir = box.group.selection.text;
var imageRetoucher = app.activeDocument.artLayers.add();
imageRetoucher.kind = LayerKind.TEXT;
imageRetoucher.textItem.contents = "Retoucher: " + ir;
imageRetoucher.textItem.font = "Helvetica";
imageRetoucher.textItem.justification = Justification.LEFT;
imageRetoucher.textItem.position = [0.5, 0.7];
imageRetoucher.textItem.size = 10;
imageRetoucher.move(GroupInfo,ElementPlacement.INSIDE)
}
else {
var imageRetoucher = app.activeDocument.artLayers.add();
imageRetoucher.kind = LayerKind.TEXT;
imageRetoucher.textItem.contents = "Retoucher: /";
imageRetoucher.textItem.font = "Helvetica";
imageRetoucher.textItem.justification = Justification.LEFT;
imageRetoucher.textItem.position = [0.5, 0.7];
imageRetoucher.textItem.size = 10;
imageRetoucher.move(GroupInfo,ElementPlacement.INSIDE)
}
var doc = app.activeDocument;
var layerParent = doc.activeLayer.parent;
if ( layerParent !== doc ) doc.activeLayer = layerParent;
layerColour("yellow");
function layerColour(colour) {
switch (colour.toLocaleLowerCase()){
case 'red': colour = 'Rd '; break;
case 'orange' : colour = 'Orng'; break;
case 'yellow' : colour = 'Ylw '; break;
case 'yellow' : colour = 'Ylw '; break;
case 'green' : colour = 'Grn '; break;
case 'blue' : colour = 'Bl '; break;
case 'violet' : colour = 'Vlt '; break;
case 'gray' : colour = 'Gry '; break;
case 'none' : colour = 'None'; break;
default : colour = 'None'; break;
}
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
desc.putReference( charIDToTypeID('null'), ref );
var desc2 = new ActionDescriptor();
desc2.putEnumerated( charIDToTypeID('Clr '), charIDToTypeID('Clr '), charIDToTypeID(colour) );
desc.putObject( charIDToTypeID('T '), charIDToTypeID('Lyr '), desc2 );
executeAction( charIDToTypeID('setd'), desc, DialogModes.NO );
};
if(box.group8.value){
if( app.documents.length > 0 ){
duplicateToAll();
}
function duplicateToAll(){
docs = app.documents;
curDoc = app.activeDocument;
for(var i = 0; i < docs.length; i++){
if(curDoc != docs[i]){
var curLayer;
try { curLayer = docs[i].activeLayer; } catch(e) {}
curDoc.activeLayer.duplicate(docs[i],ElementPlacement.PLACEATBEGINNING);
}
app.activeDocument = curDoc;
}
}
function cTID(s){return charIDToTypeID(s)}
function sTID(s){return stringIDToTypeID(s)}
}
app.preferences.rulerUnits = startRulerUnits;
}
box.close();
Copy link to clipboard
Copied
Most likely you have to change Playback Options of Actions contextual dropdown menu to Accelerated.
Copy link to clipboard
Copied
This script is called from some extension HTML panel that i made, but i got same problem when i call this script when is isolated in single file.
Copy link to clipboard
Copied
Also, in the action pallet, performance is already in accelerated mode
Copy link to clipboard
Copied
Without checking any options it took 3 seconds on slow computer with 22.3.2.
Is it too long? How much for you in both versions? Did you reset Preferences?
Copy link to clipboard
Copied
I tried solution with restarting preferences but still the same... This code is a part of original code, which lasts a few seconds longer, but the problem is not time as much as the fact that it is not aesthetically good. In previous versions of PS users run this script and they get final result in the moment, but now when they run it look very slow when they foolow every step of script. Script is very simple, i just need to create some text layers with some speific informations related to psd. Do you think that problem may be that the code is written using ScriptListener, is it possible to simplify code?
Copy link to clipboard
Copied
I tested many times on very fast computer. For 22.5.7 it took 0.75 sec., in 23.3.2 it took 0.7 sec.
It's faster in current release so better compare results trying the code on some other machine.
Copy link to clipboard
Copied
Have you run it in a debugger to see where the bottlenecks are?
Copy link to clipboard
Copied
I don t know how to complete that, because i dont have too much experience with this. I debug code vith Visual Studio Code, but i got a mesage that "No problems detected..."