Copy link to clipboard
Copied
Hello.
I'm a beginner using Scripting to manipulate Photoshop.
I would like some help form the experienced people please.
First of all, what's the latest version of ExtendScript Toolkit for Adobe Photoshop CS4?
I find my version buggy.
I have some problems.
I want to "Stamp Visible". So my script won't compromise any process done before.
I wrote the following script:
app.activeDocument.artLayers[0].copy (true); // Copying all visible Layers
app.activeDocument.activeLayer = app.activeDocument.artLayers[0]; // Setting the Active Layer so the pasted Layer be on top
app.activeDocument.artLayers.add (); // Add a layer on top, necessary for dealing with groups
var MergedLayer = app.activeDocument.paste (); // Pasting the Stamped Layer
MergedLayer.name="Merged Layer"; // Naming the Layer
And found it won't work if there's only background Layer, so I altered it:
if (app.activeDocument.artLayers[0].isBackgroundLayer == true) { // Background Condition
var BackLay = app.activeDocument.artLayers[0];
app.activeDocument.artLayers[0].isBackgroundLayer = false;
}
app.activeDocument.artLayers[0].copy (true); // Copying all visible Layers
app.activeDocument.activeLayer = app.activeDocument.artLayers[0]; // Setting the Active Layer so the pasted Layer be on top
app.activeDocument.artLayers.add (); // Add a layer on top, necessary for dealing with groups
var MergedLayer = app.activeDocument.paste (); // Pasting the Stamped Layer
MergedLayer.name="Merged Layer"; // Naming the Layer
if (BackLay != null) { // If a Background Layer existed it will make sure it goes back
BackLay.isBackgroundLayer = true;
}
I have two problems, first of all trying to run the script from ExtendScript Toolkit is causing error at the following:
if (app.activeDocument.artLayers[0].isBackgroundLayer == true) { // Background Condition
Though when I run the script from Photoshop (File -> Scripts -> Browse) it euns smoothly.
What's wrong with it?
Is there a better way to "Stamp Visible" which will work on any case (Background layer, Groups etc...).
Another question I have is what's the difference between layers[0] and artLayers[0].
Thank You.
Copy link to clipboard
Copied
Adobe knows about the problems with ESTK and is working on an update.
The following code will work with or without a background layer:
var desc = new ActionDescriptor();
desc.putBoolean( charIDToTypeID( "Dplc" ), true );
executeAction( charIDToTypeID( "MrgV" ), desc, DialogModes.NO );
Layers contains groups and artlayers. Artlayers only contains artlayers.
Copy link to clipboard
Copied
Could you elaborate on the difference between layers[] and artLayers[]?
If I want to access the upper layer in order to "Stamp Visible" all the layers beneath it what should I use?
By the way, the code you wrote won't work in some cases (There's only Background layer, Only 2 layers the top one is hidden) and not always will make the merged layer on top of the others (Only if the active layer is the top one, I tried make it active but found a problem every time I set a layer to active it will necessarily make it "Visible"). It looks it's not easy to make a "Stamp Visible" function which works for any case.
I see you manipulate actions using JavaScript.
Where can I find more info on it? I couldn't find it in the published PDF's
Thank You.
Copy link to clipboard
Copied
Could you elaborate on the difference between layers[] and artLayers[]?
layers[] contains both ArtLayer and LayerSet objects. artLayers[] contains only ArtLayer objects.
If I want to access the upper layer in order to "Stamp Visible" all the layers beneath it what should I use?
The top layer/layerset is always doc.layers[0].
I see you manipulate actions using JavaScript.
Where can I find more info on it? I couldn't find it in the published PDF's
In spite of the name 'ActionDescriptor' objects are not generally used for manipulating Actions. It is part of the the low-level PS API along with ActionReference and ActionList. Generally, actions in the Actions Palette are run via the Application.doAction method.
Copy link to clipboard
Copied
This should work with or without background and with or without the top layer being visible
var doc = app.activeDocument;// make a reference to the doc
var topLayer = doc.layers[0];// make a reference to the top layer
if ( doc.activeLayer != topLayer ) {// if the top layer is not the active layer
var cv = topLayer.visible;// store the visible state
doc.activeLayer = topLayer;// make active, which makes visible
topLayer.visible = cv;// so retore visible state
}
if ( topLayer.visible == false ) doc.artLayers.add();// if not visible add a blank layer to merge into
var desc = new ActionDescriptor();// Merge visible
desc.putBoolean( charIDToTypeID( "Dplc" ), true );
executeAction( charIDToTypeID( "MrgV" ), desc, DialogModes.NO );