Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Help: need a script to merge all layers, even if there is only one layer

Community Beginner ,
Feb 10, 2011 Feb 10, 2011

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.

TOPICS
Actions and scripting
14.7K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Valorous Hero , Feb 11, 2011 Feb 11, 2011

This should do it...


try{
    activeDocument.mergeVisibleLayers();
    }catch(e){}

Translate
Adobe
Valorous Hero ,
Feb 11, 2011 Feb 11, 2011

This should do it...


try{
    activeDocument.mergeVisibleLayers();
    }catch(e){}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 14, 2011 Feb 14, 2011

Thanks Paul, that worked.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 31, 2014 Mar 31, 2014

I'm new to using scripts and would like to know where it is that I would place this code.

Thanks!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 01, 2014 Apr 01, 2014

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.

http://i.imgur.com/sXig3kR.png

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. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 08, 2014 Aug 08, 2014

Trying to get your code to work in extendscript for CS5,but not having any joy. Is  there an equivalent for this?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 08, 2014 Aug 08, 2014

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 08, 2014 Aug 08, 2014

Right Ok, should have said I'm using Illustrator CS5. Can it be done it that?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 08, 2014 Aug 08, 2014

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 08, 2014 Aug 08, 2014

I Was trying to do it within a script

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Aug 12, 2014 Aug 12, 2014

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).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 30, 2016 Dec 30, 2016

Kinda but transparency will be lost.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 14, 2011 Feb 14, 2011

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.

JJMack
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 30, 2016 Dec 30, 2016
LATEST

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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines