Copy link to clipboard
Copied
Greetings to all
I collected some lines and came up with this code, which is to create a Smart Object for the layer, and then open the Smart Object and save the file based on the dimensions of the document
But I just want a simple modification, which is to perform this procedure on the selected layers (meaning the layers you selected) and the procedure is performed on them
is this possible??
This is the code
var currentDoc = app.activeDocument;
if (app.activeDocument.activeLayer.kind == "LayerKind.SMARTOBJECT") {
runMenuItem(stringIDToTypeID('placedLayerEditContents'))
Save ();
} else {
app.runMenuItem(stringIDToTypeID('newPlacedLayer'));
runMenuItem(stringIDToTypeID('placedLayerEditContents'));
Save ();
}
function Save () {
var doc = app.activeDocument;
var currentDoc = app.activeDocument;
var docpath = doc.path;
var activeLayer = doc.activeLayer;
var Sizze= Math.round(currentDoc.width)+ " " + Math.round(currentDoc.height)
var saveFile = File(docpath + "/" + Sizze + ".jpg");
while(saveFile.exists){
Sizze = ' '+ Sizze ;
saveFile = File(docpath + "/" +Sizze + ".jpg")
};
saveJPG(saveFile, 10);
function saveJPG(saveFile, jpegQuality) {
var jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = jpegQuality;
activeDocument.saveAs(saveFile, jpgSaveOptions, true, Extension.LOWERCASE);
};
app.activeDocument.close();
}
I just want to add some lines to perform the action on the selected layers, not just one layer
Copy link to clipboard
Copied
Copy link to clipboard
Copied
thank you sir
But I find it difficult to understand these codes, and when I put my code with this article, it did not work, and this problem appeared with me
Copy link to clipboard
Copied
I also tried the second code, but it only works on one layer, with a message showing that there is a problem with the layers
I don't know where the problem is
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
myDocument.suspendHistory("Undo script...", "main(myDocument)");
}
function main() {
var theLayers = getSelectedLayersIdx();
for (var p = 0; p < theLayers.length; p++) {
selectLayerByIndex(theLayers[p], false);
// Your code here
if (activeDocument.activeLayer.kind == "LayerKind.SMARTOBJECT") {
runMenuItem(stringIDToTypeID('placedLayerEditContents'))
} else {
app.runMenuItem(stringIDToTypeID('newPlacedLayer'));
runMenuItem(stringIDToTypeID('placedLayerEditContents'));
}
}
}
///// Functions /////
function selectLayerByIndex(index, add) {
add = undefined ? add = false : add
var ref = new ActionReference();
ref.putIndex(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);
}
}
// by paul mr
function getSelectedLayersIdx() {
var selectedLayers = new Array;
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
var desc = executeActionGet(ref);
if (desc.hasKey(stringIDToTypeID('targetLayers'))) {
desc = desc.getList(stringIDToTypeID('targetLayers'));
var c = desc.count
var selectedLayers = new Array();
for (var i = 0; i < c; i++) {
try {
activeDocument.backgroundLayer;
selectedLayers.push(desc.getReference(i).getIndex());
} catch (e) {
selectedLayers.push(desc.getReference(i).getIndex() + 1);
}
}
} else {
var ref = new ActionReference();
ref.putProperty(charIDToTypeID("Prpr"), charIDToTypeID("ItmI"));
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
try {
activeDocument.backgroundLayer;
selectedLayers.push(executeActionGet(ref).getInteger(charIDToTypeID("ItmI")) - 1);
} catch (e) {
selectedLayers.push(executeActionGet(ref).getInteger(charIDToTypeID("ItmI")));
}
}
return selectedLayers;
}
Copy link to clipboard
Copied
I have wrapped a slightly modified version of your code into a function, then called the function from the code from jazz-y in order to simplify the example:
#target photoshop
/* Start Process selected layers - from jazz-y */
var s2t = stringIDToTypeID;
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('targetLayersIDs'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
var lrs = executeActionGet(r).getList(p),
sel = new ActionReference();
for (var i = 0; i < lrs.count; i++) {
sel.putIdentifier(s2t('layer'), p = lrs.getReference(i).getIdentifier(s2t('layerID')));
(r = new ActionReference()).putIdentifier(s2t('layer'), p);
(d = new ActionDescriptor()).putReference(s2t("target"), r);
executeAction(s2t('select'), d, DialogModes.NO);
/* End Process selected layers - from jazz-y */
// Your code here:
myFunction();
}
function myFunction() {
var parentDoc = app.activeDocument;
if (app.activeDocument.activeLayer.kind == "LayerKind.SMARTOBJECT") {
runMenuItem(stringIDToTypeID('placedLayerEditContents'))
Save();
} else {
app.runMenuItem(stringIDToTypeID('newPlacedLayer'));
runMenuItem(stringIDToTypeID('placedLayerEditContents'));
Save();
}
function Save() {
var doc = app.activeDocument;
var currentDoc = app.activeDocument;
var docpath = parentDoc.path;
var activeLayer = doc.activeLayer;
var Sizze = Math.round(currentDoc.width) + " " + Math.round(currentDoc.height)
var saveFile = File(docpath + "/" + Sizze + ".jpg");
while (saveFile.exists) {
Sizze = ' ' + Sizze;
saveFile = File(docpath + "/" + Sizze + ".jpg")
};
saveJPG(saveFile, 10);
function saveJPG(saveFile, jpegQuality) {
var jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = jpegQuality;
activeDocument.saveAs(saveFile, jpgSaveOptions, true, Extension.LOWERCASE);
};
app.activeDocument.close();
}
}
Copy link to clipboard
Copied
The first question to ask is – does the script work as intended as it currently is?
I don't believe that it does.
Copy link to clipboard
Copied
Sorry sir, I don't understand what you mean
I sent you the code after adding my lines
Can you try the code to show you the problem
Copy link to clipboard
Copied
Line 1 sets the variable to the original/parent/containing layered file:
var currentDoc = app.activeDocument;
Then line 14 redefines the variable again, this time to the opened smart object document.
Then the JPEG is saved into the folder using the path of the variable of the smart object document, which is a buried temp folder if the SO is embedded.
So changing line 1 to:
var parentDoc = app.activeDocument;
Then line 15 to:
var docpath = parentDoc.path;
Will at least save the JPEG file to the parent PSD file location, rather than the temporary directory for the smart object PSB file.
So before trying to make this work for multiple selected layers, it needs to work for a single selected layer. But perhaps I misunderstood your intent.
P.S. Do you really wish to have files named such as "503 172.jpg" with 7 word spaces?
This example was when I had my rulers set to pixels, but when changing the rulers to CM I get "6 2.jpg". Rather than presuming the unit of measure, it is best to explicitly set it in the script:
https://gist.github.com/MarshySwamp/898ae3237305787d0683125166aeb480
Copy link to clipboard
Copied
Excuse me, he will know and forgive me for the prolongation and exhaustion
The code that I did works well for me as it checks the layer and makes it a Smart Object and then opens and saves it
It works fine for this step
But I would like him to perform the same procedure, but on more than one layer, not just one layer
Copy link to clipboard
Copied
If possible, very sorry
To try my code on a file that you have in it more than one layer, and to try the code on a specific layer, and it will give you an idea of ​​what I want
Copy link to clipboard
Copied
The code that I did works well for me as it checks the layer and makes it a Smart Object and then opens and saves it
It works fine for this step
By @Mohamed Hameed
I understand, but the JPEG is being saved into the smart object PSB temporary location such as the following, when the original PSD is on the desktop:
Is this what you really intend for the save path for the JPEG?
Copy link to clipboard
Copied
Ah, now I understand what you mean
You mean where do I save the image files
I sent you the code in an incomplete form, but I rely on the method of saving the save path, and then the file saves all the images to the previously saved path
I mean, I'm saving a path inside a text file, and on this path I'm saving all layers through it
Copy link to clipboard
Copied
Thank you sir, I came up with a very useful solution and at the same time it does what I want
I created an action that executes the script
Then I found a script that performs the action on the specified layers and does what is required better
Thank you very much for your interest and effort
Copy link to clipboard
Copied
Please share the link to the script.
Copy link to clipboard
Copied
I don't have a permalink
I combine lines of different codes and make code that fits what I need in my work
Copy link to clipboard
Copied
I don't have a permalink
I combine lines of different codes and make code that fits what I need in my work
By @Mohamed Hameed
That makes no sense to me when you previously wrote:
"Then I found a script that performs the action on the specified layers and does what is required better"
What I am asking is where you "found a script" so that others may also benefit. I didn't suggest this before as the question was how to do this purely in script, not recording a script into an action, then running the action from a script.
__________
EDIT – from my archive:
// https://forums.adobe.com/thread/2285411
// Change Line 15 for the action and parent action set
#target photoshop
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
myDocument.suspendHistory("operation", "main(myDocument)");
};
////////////////////////////////////
function main () {
var theLayers = getSelectedLayersIdx();
// do stuff;
// reselect layers;
for (var p = 0; p < theLayers.length; p++) {
selectLayerByIndex(theLayers[p], false);
app.doAction('Invert Action', 'Invert Set'); // Define the action to play and the action set
};
};
//
function selectLayerByIndex(index,add){
add = undefined ? add = false:add
var ref = new ActionReference();
ref.putIndex(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);
}
};
////// by paul mr;
function getSelectedLayersIdx(){
var selectedLayers = new Array;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var desc = executeActionGet(ref);
if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){
desc = desc.getList( stringIDToTypeID( 'targetLayers' ));
var c = desc.count
var selectedLayers = new Array();
for(var i=0;i<c;i++){
try{
activeDocument.backgroundLayer;
selectedLayers.push( desc.getReference( i ).getIndex() );
}catch(e){
selectedLayers.push( desc.getReference( i ).getIndex()+1 );
}
}
}else{
var ref = new ActionReference();
ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" ));
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
try{
activeDocument.backgroundLayer;
selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1);
}catch(e){
selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" )));
}
}
return selectedLayers;
};
//Jazz-y
// Run currently selected action on selected layers.jsx
#target photoshop
var s2t = stringIDToTypeID;
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('targetLayersIDs'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
var lrs = executeActionGet(r).getList(p);
(r = new ActionReference()).putEnumerated(s2t('action'), s2t('ordinal'), s2t('targetEnum'));
try {
try {
var atn = executeActionGet(r).getString(s2t('name')),
set = executeActionGet(r).getString(s2t('parentName'));
}
catch (e) { throw 'Before start select any action from actions palette!' }
for (var i = 0; i < lrs.count; i++) {
(r = new ActionReference()).putIdentifier(s2t('layer'), lrs.getReference(i).getIdentifier(s2t('layerID')));
(d = new ActionDescriptor()).putReference(s2t('target'), r);
try { executeAction(s2t('select'), d, DialogModes.NO); } catch (e) { throw e + '\nCannot select layer!' }
(r = new ActionReference()).putName(s2t('action'), atn);
r.putName(s2t('actionSet'), set);
(d = new ActionDescriptor()).putReference(s2t('target'), r);
try { executeAction(s2t('play'), d) } catch (e) { throw e + '\nCannot play action "' + atn + '" from set "' + set + '"' }
}
} catch (e) { alert(e) }
Or:
// I pretty much copy-pasted everything from NinjaScript's script,
// added couple funtions from "ES-Collection/Photoshop-Scripts/Remove Unused Layers.jsx" on GitHub,
// and edited it all to work in Photoshop 2020 :)
// Also added option to choose what type of layers you applying to.
#target photoshop
var scriptName = "Apply Action To Layers";
var scriptCreator = "Originally made by NinjaScript"
function cID (inVal) { return charIDToTypeID(inVal);}
function sID (inVal) { return stringIDToTypeID(inVal);}
var currentActionSets = getActionSets();
main();
function main()
{
app.bringToFront();
optionsDialog();
}
function optionsDialog()
{
var ButtonWidth = 110;
OpenOptionsDialog = new Window("dialog", scriptName + "... " + scriptCreator);
OpenOptionsDialog.orientation = 'column';
OpenOptionsDialog.alignChildren = 'left';
mainGroup = OpenOptionsDialog.add("group");
mainGroup.orientation = 'column';
mainGroup.alignChildren = 'left';
mainGroup.alignment = 'left';
//Group
var actionSetGroup = mainGroup.add("group");
actionSetGroup.orientation = 'row';
actionSetGroup.add("statictext",undefined, "Action Set:")
var DDActionSet = actionSetGroup.add("dropdownlist",undefined, "")
DDActionSet.preferredSize.width = 210;
for (var i = 0; i < currentActionSets.length; i++)
{
DDActionSet.add("item", currentActionSets[i]);
}
DDActionSet.selection = 0;
for (var i = 0; i < currentActionSets.length; i++){ //
if(currentActionSets[i] == "Mine"){ // Selects by default Action Set with name "Mine", instead of 1st by alphabetical
DDActionSet.selection = i; //
} //
} //
//
//Action
var actionGroup = mainGroup.add("group");
actionGroup.orientation = 'row';
actionGroup.add("statictext",undefined, "Action: ")
DDActions = actionGroup.add("dropdownlist",undefined, "")
DDActions.preferredSize.width = 210;
function populateDDActions (inSet)
{
DDActions.removeAll();
for (var i = 0; i < currentActionSets[inSet].actions.length; i++)
{
DDActions.add("item", currentActionSets[inSet].actions[i]);
}
DDActions.selection = 0;
}
DDActionSet.onChange = function()
{
populateDDActions(DDActionSet.selection.index);
}
DDActionSet.onChange();
//
//ApplyTo
var ApplyTo = mainGroup.add("group");
ApplyTo.orientation = 'row';
ApplyTo.add("statictext",undefined, "Apply To: ")
DDApplyTo = ApplyTo.add("dropdownlist",undefined, "")
DDApplyTo.preferredSize.width = 110;
DDApplyTo.removeAll();
DDApplyTo.add("item", "Selected Layers");
DDApplyTo.add("item", "Visible Layers");
DDApplyTo.add("item", "ALL Layers");
DDApplyTo.selection = 0;
//
//Run
mainGroup.add("statictext", undefined, "");
ButtonGroup = mainGroup.add("group");
ButtonGroup.orientation = 'row';
ButtonGroup.alignChildren = 'center';
ButtonGroup.alignment = 'top';
buttonRun= ButtonGroup.add("button",undefined, "Run")
buttonRun.preferredSize.width = ButtonWidth;
buttonRun.onClick = function()
{
if(DDApplyTo.selection == 0) //ToSelected
{
AllSelected = getSelectedLayersIdx();
var doc = app.activeDocument;
for(var i in AllSelected)
{
if(isLayerSet(Number(AllSelected[i])) == 0 && isLocked(Number(AllSelected[i])) == 0 && isLayerSetEnd(Number(AllSelected[i])) == 0 && isAdjustmentLayer(Number(AllSelected[i])) == 0 && isClippingLayer(Number(AllSelected[i])) != 'topClippingLayer' && isClippingLayer(Number(AllSelected[i])) != 'middleClippingLayer')
{
deselectLayers();
selectLayerByIndex(Number(AllSelected[i]),true);
var v = getLayerVisibilityByIndex(Number(AllSelected[i]));
doc.activeLayer.visible = true;
app.doAction(DDActions.selection.text, DDActionSet.selection.text);
if(v == 0)
{
doc.activeLayer.visible = false;
}
}
}
deselectLayers();
OpenOptionsDialog.close();
}
if(DDApplyTo.selection == 1) //ToVisible
{
var doc = app.activeDocument;
selectAllLayers();
var layersSelected=getSelectedLayersIdx();
var u = 0;
var w = layersSelected.length;
deselectLayers();
for(var i = 1; i < w; i++)
{
if(isLayerSet(i))
{
w++;
u++;
}
}
selectAllLayers();
for(i = layersSelected.length + u; i > 0; i--)
{
if(isLayerSet(i) == 0 && isLocked(i) == 0 && isLayerSetEnd(i) == 0 && getLayerVisibilityByIndex(i) == 1 && isAdjustmentLayer(i) == 0 && isClippingLayer(i) != 'topClippingLayer' && isClippingLayer(i) != 'middleClippingLayer')
{
deselectLayers();
selectLayerByIndex(i,true);
var v = getLayerVisibilityByIndex(i);
doc.activeLayer.visible = true;
app.doAction(DDActions.selection.text, DDActionSet.selection.text);
if(v == 0)
{
doc.activeLayer.visible = false;
}
}
}
deselectLayers();
OpenOptionsDialog.close();
}
if(DDApplyTo.selection == 2) //ToAll
{
var doc = app.activeDocument;
selectAllLayers();
var layersSelected=getSelectedLayersIdx();
var u = 0;
var w = layersSelected.length;
deselectLayers();
for(var i = 1; i < w; i++)
{
if(isLayerSet(i))
{
w++;
u++;
}
}
selectAllLayers();
for(i = layersSelected.length + u; i > 0; i--)
{
if(isLayerSet(i) == 0 && isLocked(i) == 0 && isLayerSetEnd(i) == 0 && isAdjustmentLayer(i) == 0 && isClippingLayer(i) != 'topClippingLayer' && isClippingLayer(i) != 'middleClippingLayer')
{
deselectLayers();
selectLayerByIndex(i,true);
var v = getLayerVisibilityByIndex(i);
doc.activeLayer.visible = true;
app.doAction(DDActions.selection.text, DDActionSet.selection.text);
if(v == 0)
{
doc.activeLayer.visible = false;
}
}
}
deselectLayers();
OpenOptionsDialog.close();
}
}
//
//Exit
buttonClose= ButtonGroup.add("button",undefined, "Exit")
buttonClose.preferredSize.width = ButtonWidth;
buttonClose.onClick = function() {OpenOptionsDialog.close()}
//Show window
OpenOptionsDialog.center();
var result = OpenOptionsDialog.show();
}
function getActionSets()
{
var i = 1;
var sets = [];
while (true) {
var ref = new ActionReference();
ref.putIndex(cID("ASet"), i);
var desc;
var lvl = $.level;
$.level = 0;
try {
desc = executeActionGet(ref);
} catch (e) {
break; // all done
} finally {
$.level = lvl;
}
if (desc.hasKey(cID("Nm "))) {
var set = {};
set.index = i;
set.name = desc.getString(cID("Nm "));
set.toString = function() { return this.name; };
set.count = desc.getInteger(cID("NmbC"));
set.actions = [];
for (var j = 1; j <= set.count; j++) {
var ref = new ActionReference();
ref.putIndex(cID('Actn'), j);
ref.putIndex(cID('ASet'), set.index);
var adesc = executeActionGet(ref);
var actName = adesc.getString(cID('Nm '));
set.actions.push(actName);
}
sets.push(set);
}
i++;
}
return sets;
}
function deselectLayers() {
var desc01 = new ActionDescriptor();
var ref01 = new ActionReference();
ref01.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
desc01.putReference( charIDToTypeID('null'), ref01 );
executeAction( stringIDToTypeID('selectNoLayers'), desc01, DialogModes.NO );
}
function selectLayerByIndex(index,add){
add = (add == undefined) ? add = false : add;
var ref = new ActionReference();
ref.putIndex(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){}
}
function getLayerVisibilityByIndex( idx ) {
var ref = new ActionReference();
ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "Vsbl" ));
ref.putIndex( charIDToTypeID( "Lyr " ), idx );
return executeActionGet(ref).getBoolean(charIDToTypeID( "Vsbl" ));
}
function getSelectedLayersIdx(){
var selectedLayers = new Array;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var desc = executeActionGet(ref);
if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){
desc = desc.getList( stringIDToTypeID( 'targetLayers' ));
var c = desc.count
var selectedLayers = new Array();
for(var i=0;i<c;i++){
try{
activeDocument.backgroundLayer;
selectedLayers.push( desc.getReference( i ).getIndex() );
}catch(e){
selectedLayers.push( desc.getReference( i ).getIndex()+1 );
}
}
}else{
var ref = new ActionReference();
ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" ));
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
try{
activeDocument.backgroundLayer;
selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1);
}catch(e){
selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" )));
}
}
return selectedLayers;
}
function isLayerSet(idx){
var propName = stringIDToTypeID( 'layerSection' );// can't replace
var ref = new ActionReference();
ref.putProperty( 1349677170 , propName);
ref.putIndex( 1283027488, idx );
var desc = executeActionGet( ref );
var type = desc.getEnumerationValue( propName );
var res = typeIDToStringID( type );
return res == 'layerSectionStart' ? true:false;
}
function isLayerSetEnd(idx){
var propName = stringIDToTypeID( 'layerSection' );// can't replace
var ref = new ActionReference();
ref.putProperty( 1349677170 , propName);
ref.putIndex( 1283027488, idx );
var desc = executeActionGet( ref );
var type = desc.getEnumerationValue( propName );
var res = typeIDToStringID( type );
return res == 'layerSectionEnd' ? true:false;
}
function selectAllLayers() {
var desc29 = new ActionDescriptor();
var ref23 = new ActionReference();
ref23.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
desc29.putReference( charIDToTypeID('null'), ref23 );
executeAction( stringIDToTypeID('selectAllLayers'), desc29, DialogModes.NO );
}
function getSelectedLayersIdx(){
var selectedLayers = new Array;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var desc = executeActionGet(ref);
if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){
desc = desc.getList( stringIDToTypeID( 'targetLayers' ));
var c = desc.count
var selectedLayers = new Array();
for(var i=0;i<c;i++){
try{
activeDocument.backgroundLayer;
selectedLayers.push( desc.getReference( i ).getIndex() );
}catch(e){
selectedLayers.push( desc.getReference( i ).getIndex()+1 );
}
}
}else{
var ref = new ActionReference();
ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" ));
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
try{
activeDocument.backgroundLayer;
selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1);
}catch(e){
selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" )));
}
}
return selectedLayers;
}
function isLocked(myLayer){
selectLayerByIndex(myLayer);
if(activeDocument.activeLayer.allLocked || activeDocument.activeLayer.pixelsLocked || activeDocument.activeLayer.positionLocked || activeDocument.activeLayer.transparentPixelsLocked){
return true;
}
return false;
}
function isAdjustmentLayer(){
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
return executeActionGet(ref).hasKey(stringIDToTypeID('adjustment'));
}
function isClippingLayer(layerID){
var clipInfo=false;
var ref = new ActionReference();
ref.putIndex(charIDToTypeID("Lyr "), layerID);
try{
var desc = executeActionGet(ref);
} catch(e) {
// Not a valid layer
return clipInfo;
}
var group = desc.getBoolean(stringIDToTypeID('group'));
if(group) clipInfo = 'topClippingLayer';
try{
var ref = new ActionReference();
ref.putIndex(charIDToTypeID( 'Lyr ' ), layerID+1 );
desc = executeActionGet(ref);
}catch(e){
//alert("Top layer!");
return clipInfo;
}
group = desc.getBoolean(stringIDToTypeID('group'));
if(group && clipInfo == 'topClippingLayer' ) clipInfo = 'middleClippingLayer';
if(group && clipInfo == false ) clipInfo = 'bottomClippingLayer';
return clipInfo;
};
Copy link to clipboard
Copied
There is a problem with this script, the select action does not work on selected clipping mask layers