Skip to main content
Known Participant
November 4, 2022
Question

Very slow Script

  • November 4, 2022
  • 1 reply
  • 671 views

How to write the script so fast, Because my script is very slow, please guide me, Someone told me AM Code is fast as compared to Script,

 

Anyone can tell me how to write Action Manager Code For Fast Working.

 

How to know what is DOM and AM please tell me.

 

Thanks for Advance

This topic has been closed for replies.

1 reply

Legend
November 5, 2022

@MXKS,

 

It would be helpful if you posted the code for your script in question for others here to troubleshoot.

 

Regards,

Mike

MXKSAuthor
Known Participant
November 5, 2022

is this an Action Manager Code or not?

If it is not tell me how to write this AM Code!

 

#target photoshop
//
// test.jsx
//

//
// Generated Sat Feb 13 2021 03:26:11 GMT+0530
//

cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };

//
//==================== Action 1 ==============
//
function Action1() {
// Copy
function step1(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
executeAction(cTID('copy'), undefined, dialogMode);
};

// Delete
function step2(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
desc1.putReference(cTID('null'), ref1);
var list1 = new ActionList();
list1.putInteger(95);
desc1.putList(cTID('LyrI'), list1);
executeAction(cTID('Dlt '), desc1, dialogMode);
};

step1(); // Copy
step2(); // Delete
};

 

//=========================================
// Action1.main
//=========================================
//

Action1.main = function () {
Action1();
};

Action1.main();

// EOF

"test.jsx"
// EOF

Stephen Marsh
Community Expert
Community Expert
November 5, 2022

@MXKS – It appears that you have used xtools to convert an Action to JavaScript, so yes, this is AM code. Those 49 lines of converted code are the equivalent of the following 2 lines of DOM code:

 

activeDocument.activeLayer.copy();
activeDocument.activeLayer.remove();

 

Either way, it is only two steps, copy the layer and delete.

 

AM code is faster in certain circumstances, such as an alternative to for-loops over large layer collections.

 

I just tested the 49 lines of code with a JS timer, 0.12 seconds... vs 0.11 seconds for the 2 lines of DOM code. So in this case DOM vs. AM is essentially the same.