Merging layer groups?

Hi, i was reviewing the UXP Photoshop API and i notice there isnt a merge method for layer groups.
Using the new UXP Photoshop API, how do i go about merging layers into one group AND/OR flattening/merging a GROUP into one layer?

thank you

Hi,
you can do that using batchPlay. The code for that can be recorded using the Alchemist plugin.

You need to select the layers/groups you want to merge, and then execute:

const batchPlay = require("photoshop").action.batchPlay;

const result = await batchPlay(
[
   {
      "_obj": "mergeLayersNew",
      "_isCommand": true,
      "_options": {
         "dialogOptions": "dontDisplay"
      }
   }
],{
   "synchronousExecution": false,
   "modalBehavior": "fail"
});

This code works for layers as well as for groups.
If you want to merge layers outside of a group into a layer in a group, you can select only the layers (without the group) and use the same code.

Kind Regards
Jens

hey thank you, yes i have the alchemist plugin. Im starting to see that i have to use this plugin alot. I thought the purpose of using UXP was to avoid using the batch play feature so much… with CEP there was a wealth of properties and methods but it seems with UXP we have to rely heavily on this tool. Are we still in the beta version of UXP Photoshop API? just curious.

either way, thank you so much for your help. when i run the code i get the following pop up on my screen

The command “Merge Layers” is not currently available.

Is there a .select() method or something… i believe the issue is that i have to select the current layer group.

any help would be great thank you so much!

Once again im looking at the UXP Photoshop API and dont see any methods to select the layer. How am i suppose to be able to merge layers if i cannot programmatically select a layer group? is it possible to get the Layer ID? Once again i dont see a method to get the layer ID. Theres no method to Merge() a layer group… i mean there’s so much missing. Am i missing something here? I dont know how i am suppose to code with this? Is it possible to go back to using old code without it being considered legacy? Any help would be great! Thank you.

You can select layers with batchPlay; see BatchPlay: Select layer doesn't work when multiple layers have the same name - #2 by jjdenhertog for an example.

You can see how selection works by using the Alchemist tool.

@Barkin Please include any additional information/examples you can. (Also, is this made any easier with api version 2?)

As for using the older CEP code and not being considered “legacy” – there is no provision for that.

Hello, thank you so much for your respond. I appreciate your help.
i have a question, from what i saw on one of Adobe’s sites, UXP is suppose to basically help ween off ActionPlay/BatchPlay and to have more methods and properties than ever before where more can be done using Object Oriented Programming than before. However, it seems that the ActionPlay/BatchPlay tool needs to be used more and more than ever before. Is Adobe planning to more heavily rely on ActionPlay/BatchPlay or will we eventually going to see more objects with more methods/properties to perform more tasks than ever before with one day hopefully weening off the ActionPlay/BatchPlay and using this sparingly. I just want to make sure which way the company is directing towards these tools and automation.

Are you part of the Ps prerelease? If not, I encourage you to join (cc @Erin_Finnegan). There is a version 2 API that includes more DOM APIs in 22.5 (in prerelease now), and more DOM Apis will be added in the future.

Batchplay is there for two reasons:

  1. Enable those that want to exercise Photoshop at the bare-metal level – you can do anything here Ps can do w/ actions and the like.
  2. Serve as a stopgap until the Ps DOM APIs are mature.

cc @Erin_Finnegan
okay ill give it a try. I hope you guys go the way of Adobe XD… UXP for Adobe XD is great. There is so much one can get done with the wealth of objects/classes/libraries. Alot of automation gets done. Incredibly decreasing work load and man hours. I just hope to see Photoshop go big and have a slew of libraries/objects/classes were a majority, if not all, of photoshop can be accessed through them. This would be the way to go in future towards automation and we would heavily invest millions in Adobe stock due to the fact that this will be the future. Anyway, thank you

by the way, i looked at the link you sent me… this was actually what i was attempting to do but i was not able to get the layers id programmatically. Is there a way to obtain the layers ID without using Alchemist?

DM me with the email address you want in the prerelease!

okay i sent you a direct message. Let me know of any updates! much appreciated