Copy link to clipboard
Copied
Hello dear brothers
I have this code and it puts a number of image layers into a group based on an input value
This code works well on recent versions of Photoshop
But sometimes I work on Photoshop CS5
I noticed that the code does not work on this version with a problem appearing in this line
ref. putIdentifier(charIDToTypeID("Lyr"), index);
And this is the complete code in order to be fully explained
deSelectAllLayers();
var _layers = app.activeDocument.artLayers;
var _name = prompt('Enter number : ', '');
if (_name) {
_groupLength = Number(_name);
if (!isNaN(_groupLength)) {
if (_groupLength != 0 && _groupLength <= _layers.length) {
for (var i = 0; i < _groupLength; i++) {
selectLayerByID(_layers[i].id, true);
}
groupSelectedLayers(_name);
} else {
alert('Either you entered 0 or entered number is higher than the number of layers present in the document');
}
} else {
alert('Enter value is not the number')
}
}
function groupSelectedLayers(theName) {
var desc159 = new ActionDescriptor();
var ref114 = new ActionReference();
var idlayer = stringIDToTypeID("layer");
var idordinal = stringIDToTypeID("ordinal");
var idtargetEnum = stringIDToTypeID("targetEnum");
var idnull = stringIDToTypeID("null");
var idname = stringIDToTypeID("name");
ref114.putEnumerated(idlayer, idordinal, idtargetEnum);
desc159.putReference(idnull, ref114);
desc159.putString(idname, "aaa");
executeAction(stringIDToTypeID("groupLayersEvent"), desc159, DialogModes.NO);
var desc63 = new ActionDescriptor();
var ref37 = new ActionReference();
ref37.putEnumerated(idlayer, idordinal, idtargetEnum);
desc63.putReference(idnull, ref37);
var desc64 = new ActionDescriptor();
desc64.putString(idname, theName);
desc63.putObject(stringIDToTypeID("to"), idlayer, desc64);
executeAction(stringIDToTypeID("set"), desc63, DialogModes.NO)
}
function selectLayerByID(index, add) {
add = undefined ? add = false : add
var ref = new ActionReference();
ref.putIdentifier(charIDToTypeID("Lyr "), index);
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);
}
};
function deSelectAllLayers() {
var idselectNoLayers = stringIDToTypeID("selectNoLayers");
var desc26 = new ActionDescriptor();
var idnull = charIDToTypeID("null");
var ref3 = new ActionReference();
var idLyr = charIDToTypeID("Lyr ");
var idOrdn = charIDToTypeID("Ordn");
var idTrgt = charIDToTypeID("Trgt");
ref3.putEnumerated(idLyr, idOrdn, idTrgt);
desc26.putReference(idnull, ref3);
executeAction(idselectNoLayers, desc26, DialogModes.NO);
}
Thank you for your interest and constant response and assistance to us
deSelectAllLayers();
var _layers = app.activeDocument.artLayers;
var _name = prompt('Enter number : ', '');
if (_name) {
_groupLength = Number(_name);
if (!isNaN(_groupLength)) {
if (_groupLength != 0 && _groupLength <= _layers.length) {
// NEW CODE BEG ////////////////////
for (var i = 0; i < _groupLength; i++)
{
app.activeDocument.activeLayer = _
...
Copy link to clipboard
Copied
I don't know why, that is a very generic piece of code that should work in any version. I can't test on such an old version.
Note that:
ref. putIdentifier(charIDToTypeID("Lyr"), index);
should be (no space after ref.)
ref.putIdentifier(charIDToTypeID("Lyr "), index);
(i.e. A four character code using a space at the end)
You could try changing:
ref.putIdentifier(charIDToTypeID("Lyr "), index);
To:
ref.putIdentifier(stringIDToTypeID ('layer'), index);
However, I doubt that it would help!
P.S. You could Google "selectLayerByID" and see what hits you get!
Copy link to clipboard
Copied
Thank you but when trying the code after modifying the line
I see an error in this line
Copy link to clipboard
Copied
As I wrote, I doubt it will help! It is the same thing, just expressed differently. Is the error the same or different?
Have you tried running the script directly in Photoshop, not through ESTK?
Do you have ScriptListener for CS5 to see what code it produces?
Copy link to clipboard
Copied
I am testing the code through a program
adobe extendscript toolkit CS5
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Sorry for not being familiar with the lines of this code
Is there a solution to this problem
Sometimes I work on files that contain layers of images of more than 300 or 400 images
And I want to divide those layers into groups with specified numbers entered
I don't know if I explained what was required or not
Copy link to clipboard
Copied
deSelectAllLayers();
var _layers = app.activeDocument.artLayers;
var _name = prompt('Enter number : ', '');
if (_name) {
_groupLength = Number(_name);
if (!isNaN(_groupLength)) {
if (_groupLength != 0 && _groupLength <= _layers.length) {
// NEW CODE BEG ////////////////////
for (var i = 0; i < _groupLength; i++)
{
app.activeDocument.activeLayer = _layers[i];
var r = new ActionReference();
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
_layers[i].id = executeActionGet(r).getInteger(stringIDToTypeID("layerID"));
}
deSelectAllLayers();
// NEW CODE END ////////////////////
for (var i = 0; i < _groupLength; i++) {
selectLayerByID(_layers[i].id, true);
}
groupSelectedLayers(_name);
} else {
alert('Either you entered 0 or entered number is higher than the number of layers present in the document');
}
} else {
alert('Enter value is not the number')
}
}
function groupSelectedLayers(theName) {
var desc159 = new ActionDescriptor();
var ref114 = new ActionReference();
var idlayer = stringIDToTypeID("layer");
var idordinal = stringIDToTypeID("ordinal");
var idtargetEnum = stringIDToTypeID("targetEnum");
var idnull = stringIDToTypeID("null");
var idname = stringIDToTypeID("name");
ref114.putEnumerated(idlayer, idordinal, idtargetEnum);
desc159.putReference(idnull, ref114);
desc159.putString(idname, "aaa");
executeAction(stringIDToTypeID("groupLayersEvent"), desc159, DialogModes.NO);
var desc63 = new ActionDescriptor();
var ref37 = new ActionReference();
ref37.putEnumerated(idlayer, idordinal, idtargetEnum);
desc63.putReference(idnull, ref37);
var desc64 = new ActionDescriptor();
desc64.putString(idname, theName);
desc63.putObject(stringIDToTypeID("to"), idlayer, desc64);
executeAction(stringIDToTypeID("set"), desc63, DialogModes.NO)
}
function selectLayerByID(index, add) {
add = undefined ? add = false : add
var ref = new ActionReference();
ref.putIdentifier(charIDToTypeID("Lyr "), index);
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);
}
};
function deSelectAllLayers() {
var idselectNoLayers = stringIDToTypeID("selectNoLayers");
var desc26 = new ActionDescriptor();
var idnull = charIDToTypeID("null");
var ref3 = new ActionReference();
var idLyr = charIDToTypeID("Lyr ");
var idOrdn = charIDToTypeID("Ordn");
var idTrgt = charIDToTypeID("Trgt");
ref3.putEnumerated(idLyr, idOrdn, idTrgt);
desc26.putReference(idnull, ref3);
executeAction(idselectNoLayers, desc26, DialogModes.NO);
}
Copy link to clipboard
Copied
Thank you, thank you, thank you ...
Seriously what a great programming language
And how wonderful it is to find someone useful and helpful to others
Really thank you so much for your cooperation and help to me
I wish you success always and forever