Photoshop: How do I create a separate group for every selected layer?

  • 1
  • Question
  • Updated 2 weeks ago
  • Answered
  • (Edited)
I need to put each layer in my Photoshop document into its own group. 

Ideally I'd select all my layers and have a command or action that puts them each into their own respective groups that have the same names as the layers themselves. CTRL G just works for creating one single group and names it "Group #". 

I work as a compositor in animation. For every background in every scene I have up to thirty layers. These all need to be imported into Toon Boom, but Toon Boom only imports a group as a separate layer (in other words, if I have 10 layers but no groups in my PSD file, Toon Boom will merge those ten layers into one). 

Naming and organizing layers accurately is extremely important for compositing. So if anyone has a script for this or has any brilliant ideas on how to do it faster than manually, it would make a huge difference and my thanks would be most eloquently typed in this conversation! :D
Photo of Witte Van Der Tempel

Witte Van Der Tempel

  • 8 Posts
  • 4 Reply Likes

Posted 3 weeks ago

  • 1
Photo of Max Johnson

Max Johnson, Champion

  • 429 Posts
  • 194 Reply Likes
Short of writing a script to do it, you can record actions that use the "Select next/previous layer" hotkey instead of directly selecting a layer using your mouse and they will be repeatable on any set of layers... So

  1. select the bottom most layer
  2. start recording a new action and give it a hotkey like F6 in the dialog box that appears.
  3. Start recording
  4. ctrl/cmd-g (new group)
  5. alt/opt-] (select previous layer)
  6. stop recording
Now you should have an action that, when you start at the bottom layer, will let you just mash the F6 key 30 times.
Photo of Paul Riggott

Paul Riggott

  • 359 Posts
  • 141 Reply Likes
You could see if this script will work for you Photoshop CC 2018 required and it does all layers.
www.ps-bridge-scripts.talktalk.net/download/groupsFromLayers.zip

Good luck.
Photo of Max Johnson

Max Johnson, Champion

  • 429 Posts
  • 194 Reply Likes
After that, I had a forehead slapping moment where I saw you had done the background check in other parts of the code and thought "Oh, there's like 4 different ways to check that!"
so I made this self-answering question post, for the curious:
https://feedback.photoshop.com/photoshop_family/topics/how-to-check-if-document-has-background-layer-with-jsx-javascript-script-in-photoshop
Photo of Paul Riggott

Paul Riggott

  • 359 Posts
  • 141 Reply Likes
var activeDocHasPropBGLyr = function()
{
        return activeDocument.hasOwnProperty("backgroundLayer");  
}
returns true if there is or is not a background layer.
Photo of Max Johnson

Max Johnson, Champion

  • 429 Posts
  • 194 Reply Likes
Now I am sad. But better informed. And have updated the link above.
(Edited)
Photo of Witte Van Der Tempel

Witte Van Der Tempel

  • 8 Posts
  • 4 Reply Likes
POOM! It works like a dream! I appreciate your teamwork guys, way to gooooooo!!! :D 
Thank you Paul and Max!
Love from the Netherlands <3 
Photo of Witte Van Der Tempel

Witte Van Der Tempel

  • 8 Posts
  • 4 Reply Likes
Dear Gentlemen,
As promised I will now proceed to express my gratitude with the utmost eloquence. You have both assisted a total stranger. I will remember this when we feast together in Valhalla and share our tales of victory. Your valor shines like a light brighter than Thor's lightning! 
Hahaha no but seriously this gives me something I can use and has given me some handy insights into actions! Thank you for your help and your clear communication :-)
Photo of Paul Riggott

Paul Riggott

  • 359 Posts
  • 141 Reply Likes
Please pass the scripts on to your  Toon Boom Pals if you think they may be of use.
Photo of Witte Van Der Tempel

Witte Van Der Tempel

  • 8 Posts
  • 4 Reply Likes
I totally will! I'll try to put it up on the Toon Boom Forum! I can't believe nobody else has asked for this yet...