Copy link to clipboard
Copied
I try to unlock layers/group layers, show error and below kind of message in photoshop.
The command "Set" is not currently available.
How to solve this?
That's a bug you can solve putting at top of your script this code:
sTT = stringIDToTypeID
dsc = new ActionDescriptor(), (ref = new ActionReference())
.putEnumerated(sTT('layer'), sTT('ordinal'), sTT('front'));
dsc.putReference(sTT('null'), ref), executeAction(sTT('select'), dsc)
Hi,
One another way of doing is using ScriptListener code and loop all layers. Here is the snippet for the same.
var myDoc = app.activeDocument;
var layers1 = myDoc.layers;
for (var a = 0; a < layers1.length; a++) {
if (layers1[a].visible == true) {
if (layers1[a].allLocked == true) {
// =======================================================
var idselect = stringIDToTypeID("select");
var desc146 = new ActionDescriptor();
var idnull =
...
Copy link to clipboard
Copied
Could you please post the code and a screenshot with the pertinent Panels (Toolbar, Layers, Options Bar, …) visible?
Is the Layer/Group actually locked?
Copy link to clipboard
Copied
var myDoc = app.activeDocument;
var layers1 = myDoc.layers;
for(var a=0;a<layers1.length;a++){
if(layers1[a].visible == true){
if(layers1[a].allLocked == true){
app.activeDocument.activeLayer = layers1[a];
app.activeDocument.activeLayer.allLocked = false;
}
}
}
Copy link to clipboard
Copied
On which Layer does it fail?
And you know that this wil lonly affect top-level Layers?
Copy link to clipboard
Copied
On which Layer does it fail? in start up i am facing error.
And you know that this wil lonly affect top-level Layers? no.
Copy link to clipboard
Copied
I get no problems here.
Was that the complete Script?
In DOM a document’s Layers are the top-level Layers and the Layers within a Group are that Group’s Layers.
Copy link to clipboard
Copied
Yes this completed,
If i select any group layers and run the script its working fine.
But without select group layer am facing that kind of error.
i having another function to unlock child layers in the group, but before i need to release document layers(document layer).
Copy link to clipboard
Copied
The Script you posted is missing a closing bracket at the end.
Copy link to clipboard
Copied
bracket is available after the attached image, look image right down end.
Copy link to clipboard
Copied
Hi, this is happening because when no layer is selected in layers panel, stilll you get activeLayer. I mean follow the steps
I am not sure exactly reason behind this but when you try to make it active same layer it gives this error. So if loop in reverse order, it will work.
Try this
var myDoc = app.activeDocument;
var layers1 = myDoc.layers;
for (var a = layers1.length - 1; a >= 0; a--) {
if (layers1[a].visible == true) {
if (layers1[a].allLocked == true) {
myDoc.activeLayer = layers1[a];
myDoc.activeLayer.allLocked = false;
}
}
}
Let us know if this works
Copy link to clipboard
Copied
That's a bug you can solve putting at top of your script this code:
sTT = stringIDToTypeID
dsc = new ActionDescriptor(), (ref = new ActionReference())
.putEnumerated(sTT('layer'), sTT('ordinal'), sTT('front'));
dsc.putReference(sTT('null'), ref), executeAction(sTT('select'), dsc)
Copy link to clipboard
Copied
Hi, Wow this a bug, but what is actullay a bug. I mean I just figure it out something via debug that if we set activeLayer the same which is earlier it gives this error. So I just loop in reverse order and it works but I don't know reason behind it. Could you please share more details 🙂
Copy link to clipboard
Copied
Actually I wanted to browse forum to find other similar threads in which I participated to link one of them about this bug, so maybe you'll find something more yourself, I remember there is more detailed description for this some of us investigated 😉
Copy link to clipboard
Copied
Worth finding.. 🙂
I will definitely look and find out that link. (It may possible not exists on new forum).
Copy link to clipboard
Copied
HI ,
If possible please explain explain, actually its working, i got very surprice for this.
Copy link to clipboard
Copied
Hi,
I am not sure for what part you need explantion as there are lots above.
This is what I can explain you, as mentioned above by @Kukurykus this is a bug and explanation about this bug that I can understand while debugging is Photoshop API return activeLayer as first top most layer when nothing is selected. See screen shot below
So, if you write app.activeDocument.activeLayer for second screenshot, it will not return empty, it will return what is at the top in the Layers panel but in reality it should give an error something like nothing is active. And while debugging I figure it out this and try to run your for loop in reverse order and it works.
Copy link to clipboard
Copied
It's simple, it selects top (last, counting by ActionManager) layer.
Copy link to clipboard
Copied
@Kukurykus if it's not a secret, what else are the values for ordinal enum type? front, previous, targetEnum? And most importantly - how can i find out these values myself? I found them in PIStringTerminology.h from the SDK, but they are there among many other values and it is completely incomprehensible that they can be used with .putEnumerated
Copy link to clipboard
Copied
Do many different stuff in Photoshop, and then read ScriptListenerJS.log for those values 😉
Copy link to clipboard
Copied
2 jazz-y
I came across such identifiers
"targetEnum"
"allEnum"
"front"
"back"
"previous"
"next"
"backwardEnum"
"forwardEnum"
"merged"
"hidden"
UPD. Found in PITerminology.h
#define typeOrdinal 'Ordn' // enumAll, enumFirst, enumLast, enumNext, enumPrevious, enumMiddle, enumAny, enumNone, enumTarget, enumForward, enumBackward, enumFront, enumBack, enumMerged, enumLinked.
Copy link to clipboard
Copied
oh btw, personally I found beside the above one about 3 DOM methods to activate top layer, while I remember other users came with some of them, but I think the best is which later has been found by r-bin:
(aL = activeDocument.activeLayer).link(aL)
What is funny, you can't see it's linked with itself (evan check by aL.linkedLayers as it gives undefined), but you can then unlink it (what doesn't work with another attempt):
(aL = activeDocument.activeLayer).unlink(aL)
Edit: I think 'first' and 'last' you missed before update as if I'm right they can be meet in SL log? But 'middle', 'any', 'none' and 'linked' you can try to use and show us how you did that 😉 btw I don't see 'hidden' in PITerminology.h
Copy link to clipboard
Copied
@r-bin and @Kukurykus, thx!
Copy link to clipboard
Copied
Hi,
One another way of doing is using ScriptListener code and loop all layers. Here is the snippet for the same.
var myDoc = app.activeDocument;
var layers1 = myDoc.layers;
for (var a = 0; a < layers1.length; a++) {
if (layers1[a].visible == true) {
if (layers1[a].allLocked == true) {
// =======================================================
var idselect = stringIDToTypeID("select");
var desc146 = new ActionDescriptor();
var idnull = stringIDToTypeID("null");
var ref35 = new ActionReference();
var idlayer = stringIDToTypeID("layer");
ref35.putName(idlayer, layers1[a].name);
desc146.putReference(idnull, ref35);
var idmakeVisible = stringIDToTypeID("makeVisible");
desc146.putBoolean(idmakeVisible, false);
var idlayerID = stringIDToTypeID("layerID");
var list31 = new ActionList();
list31.putInteger(6);
desc146.putList(idlayerID, list31);
executeAction(idselect, desc146, DialogModes.NO);
// =======================================================
var idapplyLocking = stringIDToTypeID("applyLocking");
var desc147 = new ActionDescriptor();
var idnull = stringIDToTypeID("null");
var ref36 = new ActionReference();
var idlayer = stringIDToTypeID("layer");
var idordinal = stringIDToTypeID("ordinal");
var idtargetEnum = stringIDToTypeID("targetEnum");
ref36.putEnumerated(idlayer, idordinal, idtargetEnum);
desc147.putReference(idnull, ref36);
var idlayerLocking = stringIDToTypeID("layerLocking");
var desc148 = new ActionDescriptor();
var idprotectNone = stringIDToTypeID("protectNone");
desc148.putBoolean(idprotectNone, true);
var idlayerLocking = stringIDToTypeID("layerLocking");
desc147.putObject(idlayerLocking, idlayerLocking, desc148);
executeAction(idapplyLocking, desc147, DialogModes.NO);
}
}
}
But this is little difficult to understand.
Copy link to clipboard
Copied
If possible, please explain this.
Copy link to clipboard
Copied
There is a great explanation of Action Code from experts of the community at below link.