Copy link to clipboard
Copied
I am trying to build an action that includes "merge all layers" or "merge visible layers". However when I record that throught the actions tool (usung the layers panel flyout dialog), if a file being batched doesn't have more than two layers or has one layer that is flat, I get an error and the actions stops. I wanted to add a step in the action to run a script that can do one of the two layer merges, and if there is only one layer will just continue without erroroing out.
Could anyone suggest some code snippets or point me the obvious answer?
Thanks so much!
- Not even a script noob yet. Please be kind.
1 Correct answer
This should do it...
try{
activeDocument.mergeVisibleLayers();
}catch(e){}
Explore related tutorials & articles
Copy link to clipboard
Copied
This should do it...
try{
activeDocument.mergeVisibleLayers();
}catch(e){}
Copy link to clipboard
Copied
Thanks Paul, that worked.
Copy link to clipboard
Copied
I'm new to using scripts and would like to know where it is that I would place this code.
Thanks!
Copy link to clipboard
Copied
Are you using Scripts (.jsx?) or Actions?
If you are brand new to both, I suggest you start with Actions since all the tools you need are already present in Photoshop. JJMack's steps are exactly what you need. Create an action set and then create an action.
Use Alt-F9 (Option-F9 or Fn-Option-F9 on a Mac or MacBook) to see the Actions palette.
Creating a new Action is the icon to the right. Do some googling and you'll see lots of help on how to create actions.
If you are writing a script you put the code Paul displays above in your .jsx file. If your question is where do you put the script? You can put it anywhere.
Copy link to clipboard
Copied
Trying to get your code to work in extendscript for CS5,but not having any joy. Is there an equivalent for this?
Copy link to clipboard
Copied
Make sure extendscript is targeting photoshop, or add this to the top of your co: #target photoshop
you could also try to use this instead of merge visable: activeDocument.flatten() that should do the same as merging visable.
Copy link to clipboard
Copied
Right Ok, should have said I'm using Illustrator CS5. Can it be done it that?
Copy link to clipboard
Copied
ah right, if your in illustrator and trying to do it:
In your Layers palette, click on the little options arrow and scroll down to "flatten artwork."
Voila.
Copy link to clipboard
Copied
I Was trying to do it within a script
Copy link to clipboard
Copied
Bob: Rather than asking in a Photoshop scripting discussion how to write Illustrator scripts you'll find answers more to your liking among the Illustrator scripting discussion(s).
Copy link to clipboard
Copied
Kinda but transparency will be lost.
Copy link to clipboard
Copied
Its aslo easy to do in an action. Record the following
Shift+Ctrl+Alt+N (Add New Empty Layer without a prompt)
Shift+Ctrl+Alt+E (Stamp Visible Layers)
Shift+Ctrl+] (move current layer to the front top of stack)
You need to record the first step because sometins stamp visible layers does nothing it depends what the current Photoshop target is. When you add a new empty layer it will be added above the current Layer and become the Photoshop target and be a visible layer. You have no idea where in the stack this layer has been added. When the curren Photoshop Target is a visble empty layer stamp visible layer will place a merge of all visible layers into that empty layer and it will still be the Photoshop Target. To record the third step you may have to first stop recording the action add some layers and target sone layer below the top of the stack that can be moved up not the background layer. Then press the record button and use "Shift+Ctrl+]" if the current layer is the top of the stack using "Shift+Ctrl+]" will not be recorded. I often start actions like this for doing things like sharpening. I convert the layer to a smart object load a edge mask alpha channel as a selection then use the smart sharpen filter as a smart filter the selection get added as a filter mask. . I then change the layers blending mode to luminosity to protect the colors and adjust the blend if gray sliders to protect the shadows and highligts more on less creates a sharpeng adjustment layer. Which can be readjusted and adjusted via its opacity adjustment slider and you can even add a layer mask to paint away over sharpened areas.
Copy link to clipboard
Copied
Ok well it's been 5 years since I asked this question, forgot the answer, looked it up in 2016, and found out I asked already in 2011. Thanks again everyone!

